var noHover = false;
function getHover() {
	return noHover;
}
function stopHover() {
	noHover = false;
}
 $(document).ready(function(){
       $(window).resize(function() {
       var wh = $(window).height() ;
	wh =  (wh < 800 ? 800 : wh);
	wh += "px";
       $(".colmask").css('height', wh);
       $(".colright").css('height', wh);
       $(".colmid").css('height', wh);
       $(".colleft").css('height', wh);
       $(".col1").css('height', wh);
       $(".col2").css('height', wh);
       $(".col3").css('height', wh);
       $(".content").css('height', wh);
       $(".secondary").css('height', wh);
	$("#rightcontent").css("left",($(window).width() > 900 ? 475: 400) + "px");
       });
	$(window).resize();
	var heightMin = videoSet.sizeMinHeight;
	var heightMaxThumb = videoSet.sizeMaxThumbHeight;
	var heightMaxVideo = videoSet.sizeMaxVideoHeight;
	var widthMin = videoSet.sizeMinWidth;
	var widthMax = videoSet.sizeMaxWidth;
						
	var currentVideo = '~';
				
	var lastVideo = '~';
					

	$("#dragContainer div").each(function() {
		$(this).hover(
				function() {
				// in handler
				indexVideo = $(this).attr("id");
				if (getHover() )  {
					return; 
				}
				for( var otherVideo in videoSet.arrayVideos ) {
															if (videoSet.arrayVideos[otherVideo].isVideoShown) continue;
															cdiv = "#" + otherVideo;
															$(cdiv).stop().animate({ height: heightMin, width: widthMin, left: 49, marginBottom: 15, marginTop: 15 }, 1500, 'easeOutCubic' );
														}
				$('#' + videoSet.arrayVideos[indexVideo].divId + '-img').attr("src",'videos/color-' + videoSet.arrayVideos[indexVideo].fileThumbnail);
				$(this).stop().animate({ height: heightMaxThumb, width: widthMax, left: 0, marginBottom: 15, marginTop: 15 }, 1500, 'easeOutQuart' );
				lastVideo = indexVideo;
			},
			function() {
				// out handler
				if (getHover() ) return;
				indexVideo = $(this).attr("id");
				if( videoSet.arrayVideos[indexVideo].isVideoShown == false ) {
															$('#' + videoSet.arrayVideos[indexVideo].divId + '-img').attr("src",'videos/' + videoSet.arrayVideos[indexVideo].fileThumbnail);
															$(this).stop().animate({ height: heightMin, width: widthMin, left: 49, marginBottom: 15, marginTop: 15 }, 1500, 'easeOutCubic' );
				}
			}
		);
		$(this).click(
			function() {
				$("#close-button").click();
				indexVideo = $(this).attr("id");
								
				if (currentVideo != '~' && indexVideo != currentVideo) {
										
															if (videoSet.arrayVideos[currentVideo].isVideoShown == true)  {
																videoSet.hidePlayer( currentVideo );
																cdiv = "#" + currentVideo;
																$(cdiv).stop().animate({ height: heightMin, width: widthMin, left: 49, marginBottom: 15, marginTop: 15 }, 1500, 'easeOutCubic' );
																videoSet.arrayVideos[currentVideo].isVideoShown = false;
															}
																
			}
									
			currentVideo = indexVideo;
			if( videoSet.arrayVideos[indexVideo].isVideoShown == false ) {
										
														$(this).stop().animate({ height: heightMaxVideo }, 1500 );
														videoSet.writePlayer( indexVideo );
														videoSet.arrayVideos[indexVideo].isVideoShown = true;
														$("#titlediv").html( videoSet.arrayVideos[indexVideo].client + "<br/><h1>" + videoSet.arrayVideos[indexVideo].title + '</h1>');
														// stop hover for three seconds
														noHover = true;
														var t = setTimeout('stopHover()',1500);
			}
		});
	});
});

