
jQuery.noConflict();
(function($) {
	$(function() {

		var clicked = false;
		var bodyClick = false;

		var bgImg = $(".interactive-menu ul li:first").find(".bottom").css("backgroundImage");
		var bgRep = $(".interactive-menu ul li:first").find(".bottom").css("backgroundRepeat");
		var bgCol = $(".interactive-menu ul li:first").find(".bottom").css("backgroundColor");
		
		$(".interactive-menu ul li .title").each( function() {
			$(this).data("fullTitle", $(this).text().replace(/^[\s\n]+|[\s\n]+$/g, '') );
		});
		
		/* Click behavior */
			$(".interactive-menu .overlay").click( function() {
			
				$(".interactive-menu ul li .title").each( function() {
					
					var txt = ($(this).data('fullTitle').length > 5) ? $(this).data('fullTitle').substr(0, 5) + "..." : $(this).data('fullTitle');
					$(this).text(txt);
				});
			
			/* li */	
				
				var id = $(this).parents("li").attr("id");
				$(".hidden-content").empty();
												
				$(this).parents("li").siblings().find(".overlay").animate({opacity: "show"}, 100);
				$(this).parents("li").siblings().css({cursor: "pointer"});
				$(this).parents("li").siblings().animate({width: "110px", height: "180px", marginTop: "0px"}, 500);
				$(this).parents("li").siblings().find(".top .hidden-title").remove();
				$(this).parents("li").siblings().find(".title").animate({opacity: "show"}, 1000);
				$(this).parents("li").siblings().find(".close").hide();
							
				$(this).parents("li").siblings().find(".hidden").hide();
				$(this).parents("li").siblings().find(".middle").css({position: "static", zIndex: "0"});
				$(this).parents("li").siblings().find(".middle").animate({height: "80px"}, 500);
				$(this).parents("li").siblings().find(".image").animate({opacity: "show"}, 1000);
				$(this).parents("li").siblings().find(".bottom").css({background: bgImg, backgroundColor: bgCol, backgroundRepeat: bgRep, backgroundPosition: "100% 0"});
				$(this).parents("li").siblings().find(".bottom .flex-div").animate({opacity: "hide"}, 500);

				$(this).parents("li").siblings().find(".top .ctl").css({backgroundPosition: "0 0"});
				$(this).parents("li").siblings().find(".top .ctr").css({backgroundPosition: "100% 0"});
				$(this).parents("li").siblings().find(".top .flex-div").css({background: "#000000"});
				
				$(this).parents("li").siblings().find(".top .flex-div .title").css({color: "#cccccc"});
				$(this).parents("li").siblings().find(".middle img").css({marginTop: "0px"});
				
			/* Current li */
				
				$(this).animate({opacity: "hide"}, 100);
				$(this).parents("li").css({cursor: "default"});
				$(this).parents("li").animate({width: "630px", height: "350px", marginTop: "-160px"}, 500);
				$(this).parents("li").find(".title").hide();
				$(this).parents("li").find(".top .flex-div").append("<div class='hidden-title'>"+$(this).parents("li").find(".hidden-title").html()+"</div>");
				$(this).parents("li").find(".close").animate({opacity: "show"}, 100);

				$(this).parents("li").find(".image").hide();
				$(this).parents("li").find(".middle").animate({height: "250px"}, 500);
				$(this).parents("li").find(".middle").css({position: "relative", zIndex: "20"});

				$(this).parents("li").find(".hidden").animate({opacity: "show"}, 500, function() {
					$(this).find(".hidden-content").load(id, function() {
						if ($(".center-block").length) {
							$(".left-block").delay(500).animate({opacity: "show"}, 1000); 
							$(".center-block").delay(1000).animate({opacity: "show"}, 1000);
							$(".right-block").delay(1500).animate({opacity: "show"}, 1000);
						}
						
						else {
							$(".left-block").delay(500).animate({opacity: "show"}, 1000); 
							$(".right-block").delay(1000).animate({opacity: "show"}, 1000);
						}
					});
				});
				$(this).parents("li").find(".bottom").css({background: "#282828"}, 500);
				$(this).parents("li").find(".bottom .flex-div").animate({opacity: "hide"}, 100);
				
				$(this).parents("li").find(".top .ctl").css({backgroundPosition: "0 100%"});
				$(this).parents("li").find(".top .ctr").css({backgroundPosition: "100% 100%"});
				$(this).parents("li").find(".top .flex-div").css({background: "#959596"});		
				
				$(this).parents("li").find(".top .flex-div .title").css({color: "#cccccc"});
				$(this).parents("li").find(".middle img").css({marginTop: "0px"});
									
				clicked = true;
				
			});			
			
		/* Close behavior */
			$(".close").click( function() {
				
				$(".interactive-menu ul li .title").each( function() {
					var txt = $(this).data('fullTitle');
					$(this).text(txt);
				});
				
				$(".hidden-content").empty();
				$(this).css({display: "none"});
				$(".left-block, .center-block, .right-block").hide();
				$(".interactive-menu ul li").siblings().find(".overlay").animate({opacity: "show"}, 100);
				$(".interactive-menu ul li").css({cursor: "pointer"});
				$(".interactive-menu ul li").animate({width: "240px", height: "180px", marginTop: "0px"}, 500);
				$(".interactive-menu ul li").find(".top .hidden-title").remove();
				$(".interactive-menu ul li").find(".title").animate({opacity: "show"}, 1000);
				
				$(".interactive-menu ul li").find(".hidden").animate({opacity: "hide"}, 100);
				$(".interactive-menu ul li").find(".middle").css({position: "static", zIndex: "0"});
				$(".interactive-menu ul li").find(".middle").animate({height: "80px"}, 500);
				$(".interactive-menu ul li").find(".image").css({marginTop: "0px"})
				$(".interactive-menu ul li").find(".image").animate({opacity: "show"}, 1000);
				$(".interactive-menu ul li").find(".bottom").css({background: bgImg, backgroundColor: bgCol, backgroundRepeat: bgRep});
				$(".interactive-menu ul li").find(".bottom .flex-div").animate({opacity: "show"}, 800);
				
				$(".interactive-menu ul li").find(".top .ctl").css({backgroundPosition: "0 0"});
				$(".interactive-menu ul li").find(".top .ctr").css({backgroundPosition: "100% 0"});
				$(".interactive-menu ul li").find(".top .flex-div").css({background: "#000000"});
				
				clicked = false;
				
			});
			
			$("body").click( function() {
				
				if (bodyClick) {
				
				$(".interactive-menu ul li .title").each( function() {
					var txt = $(this).data('fullTitle');
					$(this).text(txt);
				});
				
					$(".hidden-content").empty();
					$(".close").css({display: "none"});
					$(".left-block, .center-block, .right-block").hide();
					$(".interactive-menu ul li").siblings().find(".overlay").animate({opacity: "show"}, 100);
					$(".interactive-menu ul li").css({cursor: "pointer"});
					$(".interactive-menu ul li").animate({width: "240px", height: "180px", marginTop: "0px"}, 500);
					$(".interactive-menu ul li").find(".top .hidden-title").remove();
					$(".interactive-menu ul li").find(".title").animate({opacity: "show"}, 1000);
					
					$(".interactive-menu ul li").find(".hidden").animate({opacity: "hide"}, 100);
					$(".interactive-menu ul li").find(".middle").css({position: "static", zIndex: "0"});
					$(".interactive-menu ul li").find(".middle").animate({height: "80px"}, 500);
					$(".interactive-menu ul li").find(".image").css({marginTop: "0px"})
					$(".interactive-menu ul li").find(".image").animate({opacity: "show"}, 1000);
					$(".interactive-menu ul li").find(".bottom").css({background: bgImg, backgroundColor: bgCol, backgroundRepeat: bgRep});
					$(".interactive-menu ul li").find(".bottom .flex-div").animate({opacity: "show"}, 800);
					
					$(".interactive-menu ul li").find(".top .ctl").css({backgroundPosition: "0 0"});
					$(".interactive-menu ul li").find(".top .ctr").css({backgroundPosition: "100% 0"});
					$(".interactive-menu ul li").find(".top .flex-div").css({background: "#000000"});
					
					clicked = false;
				}
			});			
			
		/* Hover behavior */
			$(".interactive-menu ul li").mouseenter( function() {
			
				if (!clicked) {	
					$(this).find(".top .flex-div .title").css({color: "#523c8c"});
					//$(this).find(".top .flex-div .title").css({color: "#ff9933"});
					$(this).siblings().find(".top .flex-div .title").css({color: "#cccccc"});
					$(this).siblings().find(".image img").css({marginTop: "-90px"});
					$(this).siblings().find(".bottom").css({backgroundPosition: "100% 100%"});
					$(this).animate({marginTop: "-5px", marginBottom: "-5px"}, 100);
					
					$(this).find(".middle").animate({height: "90px"}, 100);
					$(this).find(".image").animate({marginTop: "5px"}, 100); 
				}
				
				bodyClick = false;
				
			});

			$(".interactive-menu ul li").mouseleave( function() { 
			
				if (!clicked) {	
					$(".interactive-menu ul li").find(".top .flex-div .title").css({color: "#cccccc"});	
					$(".interactive-menu ul li").find(".image img").css({marginTop: "0px"});
					$(".interactive-menu ul li").find(".bottom").css({backgroundPosition: "100% 0"});

					$(this).find(".middle").animate({height: "80px"}, 100);
					$(this).animate({marginTop: "0px", marginBottom: "0px"}, 100);
					$(this).find(".image").animate({marginTop: "0px"}, 100); 
				}
				
				bodyClick = true;
				
			});				
			
			$(".carousel ul li").click(function(){
				window.location=$(this).find("a").attr("href"); 
			});	
			
			$(".left-column .block-content, .right-column .block-content").height($("#content").height());
			
			$(".media-menu ul li").click(function(){
				window.location=$(this).find("a").attr("href"); 
			});	
			
			$(".animated-block").click(function(){
				window.location=$(this).find("a").attr("href"); 
			});	

	});
})(jQuery);
