
// Counts slide total before call-to-action
window.numSlides = 0;

/* No more SIFT text replacement 
if(typeof sIFR == "function"){
		sIFR.replaceElement(named({
			sSelector:".heading, #vacation h2, #content-rules h2", 
			sFlashSrc:"flash/lucida_grande.swf", 
			sColor:"#333333", sLinkColor:"#333333", 
			sWmode: "transparent", 
			sHoverColor:"#333333", 
			nPaddingTop:0, 
			nPaddingBottom:0
		}));
		sIFR.replaceElement(named({
			sSelector:"#photogroup h2",
			//sFlashVars: "textalign=center",
			sFlashSrc:"flash/lucida_grande.swf", 
			sColor:"#333333", sLinkColor:"#333333", 
			sWmode: "transparent", 
			sHoverColor:"#333333", 
			nPaddingTop:0, 
			nPaddingBottom:0
		}));
		sIFR.replaceElement(named({
			sSelector:".award h2", 
			sFlashSrc:"flash/lucida_grande.swf", 
			sColor:"#2E3F42", sLinkColor:"#2E3F42", 
			sWmode: "transparent", 
			sHoverColor:"#2E3F42", 
			nPaddingTop:0, 
			nPaddingBottom:0
		}));
}; */

$(document).ready(function() {
	
	// External link reporting
	$(".analytics").click(function() {
		var trackTag = $(this).attr("rel");
		pageTracker._trackPageview(trackTag);
	});
	
	// Preload tooltip
	if (document.images) {
		tooltipImg1= new Image(); 
		tooltipImg1.src="../images/tooltip_photo.png"; 
		tooltipImg2= new Image(); 
		tooltipImg2.src="../images/tooltip_video.png"; 
	}	
	
	if ($.browser.safari) {
   		$('#toolbar h2').css("width","262px");
		$('#toolbar #sort-fancy').css('margin-left','8px');
	}
	
	// On flash intro skip if cookie is saved
	if(window.intro == 1) {
		if(readCookie('skip') == 1)
			location.href="gallery.php";
	}
	
	//Fixes last list items from having border
	$('#footer-top a:last-child').css('border','none');
	$('#footer-bottom a:last-child').css('border','none');
	
	// Search dummy text
	$('#search').val('Search');

	// Global Nav FX
	$('#navigation li:not(.active) a').hover(function() {
		$(this).stop();
		$(this).addClass('hover');
		$(this).css({ 
	//		backgroundColor:"#007385", 
			color:"#FFFFFF" 
		});
	}, function() {
		$(this).animate({ 
	//		backgroundColor: "#004954", 
			color: "#9BB8BC" 
		}, 300);
	});
	
	// Slideshow
	if($('#slideshow').size() > 0) {
		$('#slideshow').cycle({ 
			fx:    'fade', 
			timeout: 2500,
			speed:  1000,
			slideExpr: 'img',
			after:   slideshowCount, 
			autostop: 4
		});
   }
   $('#slideshow').hover( function() {
		$('.popup').stop();
		$('.popup').animate({ 
			width: "188px"
		}, 300);
	}, function() {
		if(window.numSlides != 4) {
			$('.popup').stop();
			$('.popup').animate({ 
				width: "0px"
			}, 350);
		}
	});
   
	
	// Search FX (had to use inline styles instead of classes, IE6 was buggin it)
	$('#search-post').hover( function() {
		if($('#search.active').size() > 0)
			$(this).attr('style','background-position: 0px -72px;');
		else
			$(this).attr('style','background-position: 0px -24px;');
		var dog = $(this).attr('class');
	}, function() {
		if($('#search.active').size() > 0)
			$(this).attr('style','background-position: 0px -48px;');
		else
			$(this).attr('style', '');
	});
	$('#search').focus(function() {
		// Clears search if default text
		if($('#search').val() == 'Search')
			$('#search').val('');
		$('#search').addClass('active');
		$('#search-post').attr('style','background-position: 0px -48px;');
		$('#search-pre').addClass('active');
	});
	$('#search').blur(function() {
		// Adds search if no text
		if($('#search').val() == '')
			$('#search').val('Search');			
		$('#search').removeClass('active');	
		$('#search-post').attr('style', '');		
		$('#search-pre').removeClass('active');
	});

	// Search results FX
	
	$('#results li').hover(function() {
		$(this).css('cursor','pointer');
		$(this).find('h3 a').css('color','#004954');
		$(this).css('border','1px solid #EDEDED');
		$(this).css('background','#F7F7F7');
		
	}, function() {
		$(this).attr("style","");
		$(this).find('h3 a').attr("style","");
	});
	
	$('#results li').click(function() {
		var id= $(this).attr('lang');
		window.location='detail.php?id='+id;
		return false;
	});
	
	$('#sort-fancy ul li a').click(function() {
		var text = $(this).text();
		$('#sort-fancy p').text(text);
		$('#sort-fancy ul').hide();
		window.location='gallery.php?sort='+text.toLowerCase();;
		return false;
	});
	
	// Sort FX
	$('#sort-fancy').hover( function() {
		$(this).find('ul').show();
		$(this).addClass('hover');
	}, function() {
		$(this).find('ul').hide();
		$(this).removeClass('hover');
	});
	
	
	$('#gallery ul.square li').hover( function() {
		$(this).addClass('active');
	}, function() {
		$(this).removeClass('active');
	});
	
	// If gallery exists add tooltips
	if($('ul.square li').size() > 0) {
		$('ul.square li:not(".video") a').tooltip({
			delay: 0,
			track: true,
			top: -160,
			left: -127,
			fixPNG: true,
			showURL: false,
			bodyHandler: function() {
				var title = $(this).parent().find('.title').text();
				var subtitle = $(this).parent().find('.subtitle').text();
				var caption = $(this).parent().find('.caption').text();
				var message = '<h2>'+title+'</h2><h3>'+subtitle+'</h3><p>'+caption+'</p>';
				return message; 
			}
		});
		$('#gallery ul.square li.video a').tooltip({
			delay: 0,
			track: true,
			top: -160,
			left: -127,
			fixPNG: true,
			showURL: false,
			extraClass: "video-tooltip",
			bodyHandler: function() {
				var title = $(this).parent().find('.title').text();
				var subtitle = $(this).parent().find('.subtitle').text();
				var caption = $(this).parent().find('.caption').text();
				var message = '<h2>'+title+'</h2><h3>'+subtitle+'</h3><p>'+caption+'</p>';
				return message; 
			}
		});
	}
	// Submit buton hover
	$('#submitbtn').hover( function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	// If detail page: add tooltips
	if($('#detail .pagination').size() > 0) {
		$('.pagination .prev:not(.inactive, .video), .pagination .next:not(.inactive, .video)').tooltip({
			delay: 0,
			track: true,
			top: -155,
			left: -156,
			fixPNG: true,
			showURL: false,
			bodyHandler: function() {
				var direction = $(this).attr('class');
				if(direction == 'prev') {
					var imgsrc = $('#prev-content').find('.imgsrc').text();
					var title = $('#prev-content').find('.title').text();
					var subtitle = $('#prev-content').find('.subtitle').text();
					var caption = $('#prev-content').find('.caption').text();
				}
				if(direction == 'next') {
					var imgsrc = $('#next-content').find('.imgsrc').text();
					var title = $('#next-content').find('.title').text();
					var subtitle = $('#next-content').find('.subtitle').text();
					var caption = $('#next-content').find('.caption').text();
				}
				
				var message = '<img src="'+imgsrc+'" id="img" /><div id="text"><h2>'+title+'</h2><h3>'+subtitle+'</h3><p>'+caption+'</p></div>';
				return message; 
			}
		});
		$('.pagination .video').tooltip({
			delay: 0,
			track: true,
			top: -155,
			left: -156,
			fixPNG: true,
			showURL: false,
			extraClass: "detail-video-tooltip",
			bodyHandler: function() {
				var direction = $(this).attr('class');
				if(direction == 'prev video') {
					var imgsrc = $('#prev-content').find('.imgsrc').text();
					var title = $('#prev-content').find('.title').text();
					var subtitle = $('#prev-content').find('.subtitle').text();
					var caption = $('#prev-content').find('.caption').text();
				}
				if(direction == 'next video') {
					var imgsrc = $('#next-content').find('.imgsrc').text();
					var title = $('#next-content').find('.title').text();
					var subtitle = $('#next-content').find('.subtitle').text();
					var caption = $('#next-content').find('.caption').text();
				}
				
				var message = '<img src="'+imgsrc+'" id="img" /><div id="text"><h2>'+title+'</h2><h3>'+subtitle+'</h3><p>'+caption+'</p></div>';
				return message; 
			}
		});
	}

});

// Called from flash in splash page
function skipIntro() {
	createCookie("skip","1");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function slideshowCount() {
	window.numSlides = window.numSlides + 1;
	if(window.numSlides == 4) {
		setTimeout("$('.popup').stop();$('.popup').animate({ width: \"188px\"}, 300);",500);
	}
}

