/**
 * Home JavaScript Functions
 *
 * @author Gabriel Lemonde-Labrecque
 * @copyright 2010, SchoolSuccess inc.
 */

// var myTimeStart = (new Date()).getTime();
// var logTimes = [];
// 
// function mylog(tag) {
// 	logTimes.push({ tag: tag, time: (new Date()).getTime() });
// }
// 
// function printmylog() {
// 	var last = 0;
// 	
// 	for (var blah in logTimes)
// 	{
// 		var current = logTimes[blah].time - myTimeStart;
// 		//console.log('' + logTimes[blah].tag + ': ' + (current - last));
// 		last = current;
// 	}
// }

$(document).ready(function() {
	$('.buttonViewProfile').each(function() {
		var $this = $(this);
		var $recentTutor = $this.parents('.jsRecentTutor');
		var dbid = $recentTutor.attr('dbid');
		
		$this.click(function() {
			window.location = '/user/profile/' + dbid;
		});
	});
	
	function updateSelectedThumbnail(index) {
		$thumbs = $('.thumbs');
		$thumbs.removeClass('active');
		$thumbs.eq(index).addClass('active');
		
		var $arrow = $('.navi_slider .selectorLine img');
		$arrow.removeClass();
		$arrow.addClass('slide' + (index + 1));
	}
	
	setTimeout("TC.string.trimTextByHeight($('.jsRecentTutor .aboutme'), 155);", 500);
	setTimeout("TC.string.trimTextByHeight($('.jsRecentTutor .subjects .listing'), 30);", 500);
	
	// Hack to resize avatars generated by the slider
	$('.scollableItem.cloned img.avatar.small').center({ width: 35, height: 35 });
	
	$('.close').click(function(){
		$('.alert_request_search').hide();
	});
// 	var $mapDiv = $('#mapDiv');
// 	$mapDiv.googleMap();
// 	
// 	var latitude = TC.data.get('latitude');
// 	var longitude = TC.data.get('longitude');
// 	
// 	if (latitude != '' && longitude != '') {
// 		$mapDiv.addMarker({ image: '/images/icons/marker_here.png', iconAnchor: { x: 16, y: 46 }, coord: { x: latitude, y:  longitude} });
// 		
// 		$mapDiv.setCenter(latitude, longitude);
// 	}
// 	
// 	var tutors = TC.data.get('tutors');
// 	
// 	$.each(tutors, function() {
// 		$mapDiv.addMarker({
// 			//image: '/draw_image/marker/normal/' + searchNumber,
// 			image: 'http://icons.iconarchive.com/icons/yusuke-kamiyamane/fugue/16/minus-small-circle-icon.png',
// 			//image_highlight: '/draw_image/marker/highlight/' + searchNumber,
// 			coord: { x: this.latitude, y: this.longitude },
// 			showCircle: false,
// 			//circleRadius: this.tutor_distance,
// 			//unit: distanceUnit,
// 			//infoWindowHtml: infoWindow,
// 			alwaysShowCircle: false,
// 			neverShowCircle: true
// 			
// // 			,
// // 			onMouseOver: function() {
// // 				$this.addClass('selected');
// // 			},
// // 			onMouseOut: function() {
// // 				$this.removeClass('selected');
// // 			}
// 		});
// 		mylog('finished adding a marker');
// 	});
// 	
// 	$mapDiv.addBulkToOverlay();
// 	
// 	$mapDiv.zoomOnAllMarkers();
// 	
// 	printmylog();
	function indeed_url(url,sig) {
		var hr = url;
		var si = hr.indexOf('&jsa=');
		
		if (si > 0) 
			return url;
		
		var jsh = hr + '&jsa=' + sig;
		
		if ( jsh.indexOf('&inchal') == -1 )
			jsh += '&inchal=apiresults'; 

		return jsh; 
	}

	$('.students_seeking ul li a').click(function(e){
		e.preventDefault();
		
		var feature_item_type = $(this).prop('title');
		if (feature_item_type == 'acadam-network')
		{
			var arr = $(this).prop('href').split('/');
			
			if (arr[arr.length -1] == 'unavailable')
			{
				
				window.location = '/user/login';
			}
			else
			{
				var $dialogExternalSite = $("#dialog-external-site");
				var indeedUrl = $(this).prop('href');
				var indeedRequestId = $(this).attr('anid');
				
				$dialogExternalSite.children('.page').html('<iframe src="' + indeed_url(indeedUrl, indeedRequestId) + '" width="100%" height="500px"></iframe>');
				$dialogExternalSite.dialog('open');
			}
				
			
		}
		else
			window.location = $(this).prop('href');
	});
});

