/* *****************************************
//  WebTank javascript File
//  Title: 2012_flamencobiennale.js
//  File updated: 2012-01-20 14:00:19
// 
//  Do NOT manually edit this generated file
// **************************************** */


/* VARS */

var speed = 150;
var biennale_items = new Array();

var currentMenuItem = "";

var ratio = 0;
						
/* INIT */

$(document).ready( function() {
	
	$("#standard_left .biennale .biennale_item").each( function() {
	
		biennale_items.push( $(this) );
		
		$(this).mouseover(
		
			function () {
			
				toggleBiennale( $(this) );
				
			}
			
		);

	
	});
	
	/*  */
	
	$("#product_news_details .youtube_container").bind("mouseover" , function() {
	
		mouseOverYoutube(this);
	
	} );
	
	$("#product_news_details .youtube_container").bind("mouseout" , function() {
	
		mouseOutYoutube(this);
	
	} );
	
	//
	
	$("#product_news_details .youtube_container").bind("mouseover" , function() {
	
		mouseOverYoutube(this);
	
	} );
	
	$("#product_news_details .youtube_container").bind("mouseout" , function() {
	
		mouseOutYoutube(this);
	
	} );
	
	//
	
	$("#product_intermezzo_details .youtube_container").bind("mouseover" , function() {
	
		mouseOverYoutube(this);
	
	} );
	
	$("#product_intermezzo_details .youtube_container").bind("mouseout" , function() {
	
		mouseOutYoutube(this);
	
	} );
	
	//
	
	$(".product_program_details_mvc .youtube_container").bind("mouseover" , function() {
	
		mouseOverYoutube(this);
	
	} );
	
	$(".product_program_details_mvc .youtube_container").bind("mouseout" , function() {
	
		mouseOutYoutube(this);
		
	} );
	
	$('ul#social_media li:nth-child(4n)').css('margin-right', '0');

	/* ADD THIS WIDGET */
		
	var delay = 400;
								
	function hideMenu() {
	
		if(!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden')) {
			
			$('.hover_menu').fadeOut('fast');
			$('.custom_button').removeClass('active');
			$('.hover_menu').data('hidden', true);
			
		}
		
	}
	
	/*  */
	
	$('.custom_button, .hover_menu').mouseenter( function() {
	
		$('.hover_menu').fadeIn('fast');
		$('.custom_button').addClass('active');
		$(this).data('in', true);
		$('.hover_menu').data('hidden', false);
	
	} ).mouseleave( function() {
	
		$(this).data('in', false);
		setTimeout(hideMenu, delay);
	
	} );
	
	/*  */
	
	if( $("#homepage_center").length > 0 || $("#project_list").length > 0 ) {
	
		$('.item_half:odd').addClass('odd');
		$('.item_half:even').addClass('even');
		
		$(".item_list_half .image img").css("visibility", "hidden");
		
	}
	
	/*  */
	
	if( $("#standard_right").length > 0 ) {
	
		$("#menu_overview").addClass("active");
								
		//
		
		if( $("#submenu ul li").length == '0' ) {
			
			$("#submenu").remove();
		
		}
	
		//
		
		$("#submenu li:last").css("margin-top", "20px");
	
		/*  */
		
		$("a[class^='intermezzo_image']").fancybox();
	
	}
	
	/*  */
	
	if( $(".programm_list_mvc").length > 0 ) {
	
		$('.product:odd').addClass('odd');
		$('.product:even').addClass('even');
	
	}
		
} );

$(window).load( function() {

	if( $("#homepage_center").length > 0 || $("#project_list").length > 0 )	 {
	
		$(".item_list_half .image img").each( function() {
							
			$(this).css("width", "280px");
			
			//
			
			if( $(this).height() < 203 ) {
			
				ratio = 203 / $(this).height();
				
				//
				
				$(this).css("height", "203px");
				$(this).css("width", ( $(this).width() * ratio ) + "px");
			
			}
			
			//
			
			$(this).css("visibility", "visible");
			
		} );		
		
	}
	
	/*  */
	
	if( $(".programm_list_mvc").length > 0 ) {
	
		$(".products .product .image img").each( function() {
							
			$(this).css("width", "280px");
			
			//
			
			if( $(this).height() < 203 ) {
			
				ratio = 203 / $(this).height();
				
				//
				
				$(this).css("height", "203px");
				$(this).css("width", ( $(this).width() * ratio ) + "px");
			
			}
			
			//
			
			$(this).css("visibility", "visible");
			
		} );
	
	}
	
	/*  */
	
	if( $(".product_news_details_mvc").length > 0 ) {
	
		$("a[class^='photobook_image']").fancybox();
							
		$('.image:nth-child(4n)').addClass('last');
		
	}
	
	/*  */
	
	if( $("#project_details").length > 0 ) {
	
		$("a[class^='photobook_image']").fancybox();
							
		$('.image:nth-child(4n)').addClass('last');
		
	}
	
	/*  */

	$("#homepage_center .item_half:odd").addClass("odd");
	$("#homepage_center .item_half:even").addClass("even");
	
	$("#presskit_images .product:odd").addClass("odd");
	$("#presskit_images .product:even").addClass("even");
	
	$(".city:first").css("margin", "0 0 10px 0");

	$("#program_book p").css("margin-top", ($('#program_book .program_book_image').height() - $('#program_book p').height()) / 2);
	
	/*  */
	
	toggleBiennale( $("#standard_left .biennale .biennale_item:first") );
	
	//
	
	backButton();
} );

/* FUNTIONS */

function setMenuItem(element) {
	
	if( $(".archive_overview").length > 0 ) {
	
		$(".archive_overview").hide();
		
		//
		
		$(".archive_details_mvc").html("<img src='./images/editorial/id=900.gif' alt='' class='loader' />");
		
	}
	
	if( $(".programm_list_mvc").length > 0 ) {
	
		$(".programm_list_mvc").hide();
		
		//
		
		$(".archive_details_mvc").html("<img src='./images/editorial/id=900.gif' alt='' class='loader' />");
		
	}
	
	if( $(".media_list_mvc").length > 0 ) {
	
		$(".media_list_mvc").hide();
		
		//
		
		$(".archive_details_mvc").html("<img src='./images/editorial/id=900.gif' alt='' class='loader' />");
		
	}
	
	/*  */
	
	currentMenuItem = $(element).attr("id");
		
	//
	
	$(".menu").each( function() {
								
		if( $(this).attr("id") == currentMenuItem ) {
		
			if( $(this).hasClass("inactive") ) $(this).removeClass("inactive");
			
			$(this).addClass("active");
			
			if( $("#archive_menu li ul li a").hasClass("active") ){
		
				$("#archive_menu span#menu_program").addClass("active");
				
			} else {
				
				if( $("#archive_menu span#menu_program").hasClass("active") ) $("#archive_menu span#menu_program").removeClass("active"); 
				
			}
		
		} else {
		
			if( $(this).hasClass("active") ) $(this).removeClass("active"); 
			
			$(this).addClass("inactive");
			
			if( $("#archive_menu li ul li a").hasClass("active") ){
		
				$("#archive_menu span#menu_program").addClass("active");
				
			} else {
				
				if( $("#archive_menu span#menu_program").hasClass("active") ) $("#archive_menu span#menu_program").removeClass("active"); 
				
			}
		
		}
	
	} );
	
	//

	return true;			
	
}

function mouseOverYoutube(e){

	$(e).stop();
	$(e).children(".movie").stop();
	
	//
	
	$(e).animate({
		height: $(e).children(".movie").height() 
	}, speed, function() {
	});

	$(e).children(".movie").animate({
		top: 0
	}, speed, function() {

	});
	
}
		
function mouseOutYoutube(e){
	
	$(e).stop();
	$(e).children(".movie").stop();
	
	//
	
	$(e).animate({
		height: 215
	}, speed, function() {
		
	});

	$(e).children(".movie").animate({
		top: (215+30-($(e).children(".movie").height()))/2
	}, speed, function() {

	});

}

function setYoutube(){

	$(".youtube_container").bind("mouseover" , function() {
	
		mouseOverYoutube(this);
	
	} );
	
	$(".youtube_container").bind("mouseout" , function() {
	
		mouseOutYoutube(this);
	
	} );

}

function toggleBiennale(element) {

	for( var i = 0; i < biennale_items.length; i++ ) {
			
//		console.log(biennale_items[i].attr("class"));
		
		//
		
		biennale_items[i].stop();
		
		//
		
		biennale_items[i].unbind("mouseover");
		
		//
		
		if( element.attr("class") != biennale_items[i].attr("class") ) {
		
			biennale_items[i].animate( {
			
				height: "30px"
				
				}, 
				
				speed, 
				
				function() {
				
					$(this).bind("mouseover", function() {
					
						toggleBiennale( $(this) );
						
					} );
					
					//
					
					backButton();
					
				}
				
			);
		
		} else {
		
//			console.log( ( biennale_items[i].children(".content").height() + "px" ) );
			
			biennale_items[i].animate( {
			
				height: ( biennale_items[i].children(".content").height() + "px" )
				
				}, 
				
				speed, 
				
				function() {
				
					$(this).bind("mouseover", function() {
					
						toggleBiennale( $(this) );
					
					} );
					
					//
					
					backButton();
					
				}
				
			);
		
		}
	
	}
	
}

function setLastArticle() {

	$(".media_list_mvc .article:last").css("border", "none");
	
}

function setFancybox() {

	$("a[class^='media_fancy']").fancybox();

}

function setFancyboxProgamDetails() {

	$("a[class^='photobook_image']").fancybox();

}

function setNth4ProgrammDetails() {

	$('.image:nth-child(4n)').addClass('last');

}

function backButton() {

//	console.log( ( $(".standard_left_mvc").height() + 100 ) + " - " + $(".center").height() );

	if( ( $(".standard_left_mvc").height() + 100 ) >= $(".center").height() && $(".center .back img").length > 0 ) {
	
		$(".center .back img").hide();
		
	}

}
