// JavaScript Document
$(function(){
		   
$(".work_dtl_panel").each(function(){
	$(this).attr("expanded",eval(($('.work_dtl_panel_title',$(this)).height())+($('.work_dtl_panel_dtl',$(this)).height())));
	$(this).attr("collapsed",eval(($('.work_dtl_panel_title',$(this)).height())));										  
	//alert($(this).css("franco"));
	//my_var_inc++;
	$(this).css("height",eval(($('.work_dtl_panel_title',$(this)).height())));										  
});		   
/*		   $('.work_dtl_panel').click(function(){
												  if($('.work_dtl_panel_dtl', $(this)).is(":hidden")){
													  //alert("boby");
													  $('.work_dtl_panel_dtl',$(this)).slideDown(150);
												  } else {
													  //alert("giblets");
													  $('.work_dtl_panel_dtl',$(this)).slideUp(150);													  
												  }
												  });
*/
	var my_to;
	var my_to2;
	updateCurrentSlide = function(){
		if($("#flashStage").size() != 0){
			$("#flashStage").remove();
//alert("it is set");
		}
		$(".work_dtl_panel").each(function(){
		var myGallery = $(this).parent().attr('id');									
		var firstSlide = (eval($(".slider").index($('.'+myGallery+' .slider:first'))))+1;
		var lastSlide = (eval($(".slider").index($('.'+myGallery+' .slider:last'))))+1;
		var currSlide = 1+(eval($("#slide_navigation a").index(($('#slide_navigation a.activeSlide')))));
		var totSlides = (eval($("#slide_navigation a").size()));
		var theSlide = eval((currSlide-firstSlide)+1);
		var panelID = '';
		var currIDslide = currSlide-1;
		
		if(currSlide == 1){
			collapse_all();
		}
		if(currSlide >= firstSlide && currSlide <= lastSlide){
			var currID = get_slide_html(currIDslide);
			if(is_slide_a_video(currIDslide)){
					   var holderID = get_holder_id(currIDslide);
					   
					   var $stage = $("<div id='flashStage'></div>");
					   $("#"+holderID).append($stage);
					   $stage.show();
					   //$stage.html("<h1>Hello World!</h1");
					   load_video(holderID);
					   //$(holderID+" #flashStage").html("YOU ARE LOADED");
//					   $("#flashStage").html("<h1>OH GOSH</h1>");
					   //$(this).html("<h1>OH GOSH</h1>");
					   }
			//alert(""+myGallery+" "+theSlide+""); 
			//var my_slider = $(this).attr('id');
			//alert(my_slider);
			//var my_selector = "#gallery1 .sub_slide_count";
			$('#'+myGallery+' .sub_slide_current').html(theSlide);
			//alert(theSlide);
			var panelID = "#"+myGallery;
			
			//alert($(this).parent().attr('id'));
			$(this).addClass('thisClick');
			$('.grower',$(this)).fadeIn(50);
			$('.grower',$(this)).animate({width:266},50);

			collapse_others();
			$(this).removeClass('thisClick');
			$('.work_dtl_panel').removeClass('active');
			$(this).addClass('active');	
			$(this).width(266);
			$(this).animate({height:($(this).attr("expanded"))},300);
			$('.work_dtl_panel_dtl',$(this)).slideDown(300);

		}
		/*if(panelID != ''){
		alert(panelID);
		$("panelID .work_dtl_panel").addClass('thisClick');
		collapse_others();
		$("panelID .work_dtl_panel").removeClass('thisClick');
		$('.work_dtl_panel').removeClass('active');
		panelID.addClass('active');	
		panelID.width(266);
		panelID.animate({height:(panelID.attr("expanded"))},300);
		$('.work_dtl_panel_dtl',panelID).slideDown(300);
		}*/
		 //alert(""+ currSlide +" "+ totSlides +" "+ firstSlide +" "+ lastSlide +"");
		 //alert(eval((currSlide-firstSlide)+1));
		 });
	 };
     fadeTagMenu = function(){$('#view_all_tags_menu, #view_all_tags_over').fadeOut(240)};
	 collapse_others = function(){
		 $('.work_dtl_panel').each(function(){
										if(false == $(this).hasClass('thisClick')){
										 if(true == $(this).hasClass('active')){
											$(this).width(266);
										 	$(this).animate({height:$(this).attr("collapsed")},240);
											$('.grower',$(this)).animate({width:256},50);
											$('.grower',$(this)).fadeOut(50);
										 	//$('.work_dtl_panel_title_over, .work_dtl_panel_dtl',$(this)).fadeOut(240);
											$('.work_dtl_panel_dtl',$(this)).fadeOut(240);
										 }
										}
										 })
		 };
	collapse_all = function(){
		 $('.work_dtl_panel').each(function(){
										//if(false == $(this).hasClass('thisClick')){
										 if(true == $(this).hasClass('active')){
											$(this).width(266);
										 	$(this).animate({height:$(this).attr("collapsed")},240);
											$('.grower',$(this)).animate({width:256},50);
											$('.grower',$(this)).fadeOut(50);
										 	//$('.work_dtl_panel_title_over, .work_dtl_panel_dtl',$(this)).fadeOut(240);
											$('.work_dtl_panel_dtl',$(this)).fadeOut(240);
											$(this).removeClass('active');
										 }
										 
										//}
										 })
		 };
			   //$('a').animate( { height:515 }, 4500);
		   //alert("bob");

	$('#work_subfeat_swap a').hover(function(){
		$('div div.sf_marker',$(this)).animate({top:'0px'},200);//{queue:false, duration:420, easing:"cubicEaseOut"});
		//$('body').animate({backgroundColor:'black'},220);
		},function(){
		$('div div.sf_marker',$(this)).animate({top:'-58px'},200);//{queue:false, duration:420, easing:"cubicEaseOut"});
		//$('body').animate({backgroundColor:'red'},220);
	})
	$('.work_feat_item a').hover(function(){
		$('.wf_description',$(this)).animate({height:72},200);//{queue:false, duration:220, easing:"quartEaseOut"});
		},function(){
		$('.wf_description',$(this)).animate({height:62},200);//{queue:false, duration:220, easing:"quartEaseOut"});
	});
	$('#WD_view_all_tags, #view_all_tags').hover(function(){
		clearTimeout(my_to);
		$('#view_all_tags_over').fadeIn(100);	
	},function(){
		my_to = setTimeout(fadeTagMenu,400);		
		//$('#view_all_tags_menu').removeClass('onTop');
	})
	$('#WD_view_all_tags, #view_all_tags').click(function(){
		//$('#l2_subhead').addClass('onTop');
		//$('#view_all_tags_menu').animate({opacity:100},540);
		$('#view_all_tags_menu').fadeIn(200);
	});
//detail nav
//    fadeDtlMenu = function(){$('.work_dtl_panel_title_over, .work_dtl_panel_dtl').fadeOut(240)};
															   
hide_see_work = function(){
										if( false != $("#see_the_work").hasClass('unclicked')){
											$("#see_the_work").removeClass('unclicked');
											$("#see_the_work").hide();
											$("#work_dtl_nextBTN, #work_dtl_nextBTN_bg").fadeIn(200);
											
											$('#work_dtl_slideshow *, .work_dtl_panel_holder *, #see_the_work').unbind('click',hide_see_work);
										}
};
	var work_clickStart = function(){
									  $("#work_dtl_slides").cycle(1);
									  $('#see_the_work').unbind('click',work_clickStart);
									  };
	$('#see_the_work').bind('click',work_clickStart);

	$('#work_dtl_slideshow *, .work_dtl_panel_holder *, #see_the_work').bind('click', hide_see_work);

										
	$('#work_dtl_prevBTN_half').hover(function(){
											   if(false == $('#see_the_work').hasClass('unclicked')){
															$('#work_dtl_prevBTN, #work_dtl_prevBTN_bg').show();//fadeIn(200);
											   }},function(){
												   if(false == $('#see_the_work').hasClass('unclicked')){
													   		$('#work_dtl_prevBTN, #work_dtl_prevBTN_bg').fadeOut(200);
												   }});
	$('#work_dtl_nextBTN_half').hover(function(){
											   if(false == $('#see_the_work').hasClass('unclicked')){
															$('#work_dtl_nextBTN, #work_dtl_nextBTN_bg').show();//fadeIn(200);
											   }},function(){
												if(false == $('#see_the_work').hasClass('unclicked')){
															$('#work_dtl_nextBTN, #work_dtl_nextBTN_bg').fadeOut(200);
												}});

	$('.work_dtl_panel').hover(function(){
		//clearTimeout(my_to2);
		if(false == $(this).hasClass('active')){
			//$('.work_dtl_panel_title_over',$(this)).fadeIn(100);
			$('.grower',$(this)).fadeIn(50);
			$('.grower',$(this)).animate({width:266},50);
		}
	},function(){
		//my_to2 = setTimeout(fadeDtlMenu,400);		
		//my_to2 = setTimeout(function(){
										if(false == $(this).hasClass('active')){
											$('.grower',$(this)).animate({width:256},50);
											$('.grower',$(this)).fadeOut(50);
											//$('.work_dtl_panel_title_over, .work_dtl_panel_dtl',$(this)).fadeOut(240);
											//$('.work_dtl_panel_dtl',$(this)).fadeOut(140);
											//$(this).animate({height:$(this).css("collapsed")},240);
										}
		//							 },400);		
		//$('#view_all_tags_menu').removeClass('onTop');
	})

	$('.work_dtl_panel').click(function(){
		//$('#l2_subhead').addClass('onTop');
		//$('#view_all_tags_menu').animate({opacity:100},540);
		//alert($(this).attr('slide'));
		//$('#work_dtl_slides').cycle(eval($(this).attr('slide')));
		var myGallery = $(this).parent().attr('id');
		//alert(myGallery);
		//var fs = (eval($(".slider").index($('.'+myGallery+' .slider:first'))));
		//var ls = (eval($(".slider").index($('.'+myGallery+' .slider:last'))));
		$('#work_dtl_slides').cycle(eval($(".slider").index($('.'+myGallery+' .slider:eq(0)'))));
		//updateCurrentSlide();
		/*$(this).addClass('thisClick');
		collapse_others();
		$(this).removeClass('thisClick');
		$('.work_dtl_panel').removeClass('active');
		$(this).addClass('active');	
		$(this).width(266);
		$(this).animate({height:($(this).attr("expanded"))},300);
		$('.work_dtl_panel_dtl',$(this)).slideDown(300);  */  //fadeIn(200);
		//$(this).animate({height:$(this).css("expanded")},200);
	});

// end detail nav
$("#work_cat_feat_desc, .work_feat_item:first , div.work_subfeature").addClass('margin_r_16');	
$("div.work_subfeature:eq(3), div.work_subfeature:eq(7),, div.work_subfeature:eq(11), div.work_subfeature:eq(15), div.work_subfeature:eq(19), div.work_subfeature:eq(23), .work_feat_item:last").removeClass('margin_r_16');
$("#work_dtl_prevBTN, #work_dtl_nextBTN, #work_dtl_prevBTN_bg, #work_dtl_nextBTN_bg, #view_all_tags_menu, #view_all_tags_over, .work_dtl_panel_title_over, .work_dtl_panel_dtl, .grower").hide();
$(".grower").width(256);
$(".work_dtl_panel_holder").each(function(){
										  
var my_slider = $(this).attr('id');
//alert(my_slider);
//var my_selector = "#gallery1 .sub_slide_count";
$('#'+my_slider+' .sub_slide_count').html($('.'+my_slider+' .slider').size());
										  });
//$(".gallery2").each(function(){
//eval(1+$(".slider").index($('.gallery2 .slider:eq(0)')));
	//						  });
//my_var_inc = 1;

// alert(eval($('.work_dtl_panel_title_holder:first').height())); 
//$("#WD_view_all_tags2,#WD_view_all_tags,#view_all_tags,#work_dtl_panels").css("visibility","collapse");
							 
							 //var mo = setTimeout(function(){
							 //$("#WD_view_all_tags2,#WD_view_all_tags,#view_all_tags,#work_dtl_panels").show();
							 $("#home_slideshow, #home_slideshow *, #work_dtl_slideshow, #work_dtl_slideshow *, #WD_view_all_tags2, #WD_view_all_tags2 *, #WD_view_all_tags, #WD_view_all_tags *, #view_all_tags,  #view_all_tags *, #work_dtl_panels,  #work_dtl_panels *").css("visibility","visible");
							 $(".tag_menu_hr:last").css("visibility","hidden");
							 //$('object').css('display','none');
							 //showObject = function(){$('object').css('display','block');};
							 //hideObject = function(){$('object').css('display','none');};
							 //alert("jambo");
							 //},100);
							 
var container = $('#work_dtl_slideshow');
var slides = $('li',container);
var get_slide_html = function(slide_number)
{return $(slides[slide_number]).html();}
var is_slide_a_video = function(slide_number)
{return $('.video_slide',$(get_slide_html(slide_number)).parent()).size()==true}
var get_holder_id = function(slide_number)
{return $('.flashcontent',$(get_slide_html(slide_number))).attr('id')}
var load_video_if_necessary = function(slide_number)
{if(is_slide_a_video(slide_number))
{
	//alert("jorb");
	var video_path=$('.vid_url').html()
	id=$('#odoslide_active .video_slide .flashcontent').attr('id')
	$('#flashStage').flash({swf:'/scweb_assets/swf/vidplayerV1.swf' ,width:'705' ,height:'396' ,params:{wmode:'transparent'},data:'/scweb_assets/swf/vidplayerV1.swf' ,flashvars:{flvPath:video_path/*, imgPath:'http://odopod.com/assets/images/white-gold_video-still.jpg'*/}});
//,imgPath:$('#odoslide_active img').attr('src')
}
};
var load_video = function(holderID)
//{if(is_slide_a_video(slide_number))
{
	//alert("jorb");
	var video_path=$('.vid_url',"#"+holderID).html()
	//alert(video_path);
	var id=holderID;//$('#odoslide_active .video_slide .flashcontent').attr('id')
	///assets/swf/detail_player.swf
	//
	$("#flashStage").flash({swf:'/scweb_assets/swf/vidplayerV1.swf' ,width:'705' ,id:id ,height:'396' ,params:{wmode:'transparent'},data:'/scweb_assets/swf/vidplayerV1.swf' ,flashvars:{flvPath:video_path/*, imgPath:'http://odopod.com/assets/images/white-gold_video-still.jpg'*/}});
//,imgPath:$('#odoslide_active img').attr('src')
	//$("#flashStage").hide();
	//$("#flashStage").show();
//}
};
//load_video_if_necessary(1);

});