
jQuery.easing.def = "easeOutCubic";

function clearSearch() {
  if($(".search .gsc-input").length > 0) {
	clearInterval( searchLoaded );
    $(".search .gsc-input").css({"background":"none"});
	$(".search .gsc-input").focus(function() {
	  $(this).css({"background":"none"});
  	});
	$(".search .gsc-input").blur(function() {
	  $(this).css({"background":"none"});
  	});
	
	$(".gsc-search-button").val("");
  }
}

var searchLoaded = setInterval('clearSearch()', 100);



var windowHeight = $(window).height();
var documentHeight = $(document).height();

var nextLoad = "row3";

function loadDivs(anon) {

	var v = $(anon + "> div").css('visibility', 'hidden'), cur = 0;
	
	for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);	
	
	function fadeInNextDIV() {
			
			v.eq(cur++).css('visibility','visible').hide().fadeIn(500, function(){
				$(this).find("a:first img").delay(500).fadeIn(500);
			});
			
			if(cur != v.length) setTimeout(fadeInNextDIV, 150);

	}
	fadeInNextDIV();
}
loadDivs(".row");
/*if(windowHeight > 910){
	nextLoad = $("#" + nextLoad).next("span").attr("id");
	//alert(nextLoad);
	$("#" + nextLoad + " > div").css({"display":"block"});
	
	loadDivs(".page1");
	loadDivs("#"+nextLoad);
	
	var nextLoad = "row4";
	
}else{
	loadDivs(".page1");
	nextLoad = $("#" + nextLoad).next("span").attr("id");
	//alert(nextLoad);
	$("#" + nextLoad + " > div").css({"display":"block"})
	loadDivs("#"+nextLoad);
	
	var nextLoad = "row4";
}*/



/*HOMEPAGE*/

	/*$(window).scroll(function () {
		var windowHeight = $(window).height();

		var containerHeight = $(document).height();
		var difference = containerHeight - windowHeight;

		var position = $(window).scrollTop();
		//alert(position);
		if (position > difference-7) {

			nextLoad = $("#" + nextLoad).next("span").attr("id");	
			$("#" + nextLoad + "> div").css({"display":"block"}).fadeIn(600);
			loadDivs("#" + nextLoad);
		} else {

		}
	});*/

	
	
/*HOMEPAGE*/
		
$(".gridCont span > div > a.showDescription").click(function(){
	//$(this).next(".description").animate({"left":"0px"}, 300, "easeOutCubic");
	$(".description").fadeOut();
	$(this).next(".description").fadeIn();
	return false;
});
$(".btn_close").click(function(){
	//$(this).parent(".description").animate({"left":"354px"}, 300, "easeOutCubic");
	$(this).parent(".description").fadeOut();
	return false;
});


$(".box2x2 a.mainLink .current").css({"left":"0px"});

function rotateBox(){
	
	var nextRotation = $(".box2x2 a.mainLink .current").next(".rotation");
	
	if(nextRotation.length == 0){
		$(".box2x2 a.mainLink .current").css({"z-index":"5"});
		$(".box2x2 a.mainLink .rotation:first").css({"z-index":"10", "left":"354px"});
		$(".box2x2 a.mainLink .rotation:first").delay(8000).animate({"left":"0px"}, 500, "easeOutCubic", function(){
			$(".box2x2 a.mainLink .current").css({"left":"354px"}).removeClass("current");
			$(this).addClass("current");
			rotateBox();
		});
	}else{
		$(".box2x2 a.mainLink .current").css({"z-index":"5"});
		nextRotation.css({"z-index":"10", "left":"354px"});
		$(nextRotation).delay(8000).animate({"left":"0px"}, 500, "easeOutCubic", function(){
			$(".box2x2 a.mainLink .current").css({"left":"354px"}).removeClass("current");
			$(this).addClass("current");
			rotateBox();
		});
	}
	
};
rotateBox();


$(".sortCategories").toggle(									
	function(){
		$(".categories").fadeIn(800);
	},
	function(){
		$(".categories").fadeOut(800);
	});		


/* Light Boxes */
$(".lightBox").css({"height":documentHeight});
	
	function launchVideo(whichVideo){
	
		if(whichVideo.substring(0,4) == "http"){
			
			jwplayer('videoPlayer').setup({
			'id': 'playerID',
			'width': '480',
			'height': '360',
			'stretching': 'exactfit',
			'autostart': true,
			'file': whichVideo,			
			'modes': [
			{type: 'flash', src: '/assets/flash/player.swf'},
			{type: 'html5'},
			{type: 'download'}
			]
			});
			
		}else{
			
			jwplayer('videoPlayer').setup({
			'id': 'playerID',
			'width': '480',
			'height': 'auto',
			'stretching': 'none',
			'autostart': true,
			'levels': [ 
			{ file: '/assets/video/'+whichVideo+'.mp4' },
			{ file: '/assets/video/'+whichVideo+'.ogv' }
			],
			'modes': [
			{type: 'flash', src: '/assets/flash/player.swf'},
			{type: 'html5'},
			{type: 'download'}
			]
			});
						
		}
	}	
	
	$(".launchVideoOnly").click(function(){
		var videoContent = $(this).attr("href");
		
		$(".lightBox").html("<div class='videoBox'><img src='/assets/images/close_lb.gif' onclick='closeLightBox();' class='close' /><div id='videoPlayer'></div></div>");
		
		$(".lightBox").fadeIn("slow", function(){
			launchVideo(videoContent);
		});
		
		return false;
	});
	
	$(".launchVideoAndText").click(function(){
		var videoContent = $(this).attr("href");

		var videoText = $(this).next(".videoText").html();
		
		$(".lightBox").html("<div class='videoBoxAndSideBar'><img src='/assets/images/close_lb.gif' onclick='closeLightBox();' class='close' /><div id='videoPlayer'></div><div class='sideBar'></div></div>");
		
		$(".lightBox").fadeIn("slow", function(){
			launchVideo(videoContent);
			$(".lightBox .videoBoxAndSideBar .sideBar").html(videoText);
		});
		
		return false;
	});
	
	function closeLightBox(){
		$(".lightBox").html("").fadeOut();
		return false;
	};
	
	
/* EMAIL VALIDATE */

/*function validateEmail(inputVal) {
	var duplicateFound = 0;
	var atpos=inputVal.indexOf("@");
	var dotpos=inputVal.lastIndexOf(".");

	for(i=0;i<inputVal.length;i++){
		if(inputVal.charAt(i) == "@") duplicateFound++;
	}
	
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=inputVal.length || duplicateFound > 1) {
		alert('Please use a valid email address.');
		return false;
	} else {
		return true;
	}
}*/

