/* Javascript Document for Handle Creativ Art - Werbeagentur */
/*
	created by: Klaus Hoermann <klaus@3b-solutions.net>
	created for: Handle Creativ Art - Werbeagentur
	Client: Hotel Wiesental
	Description: Contains all JQuery stuff for the basic root template.
	Copyright: (C) 3B-Solutions Klaus Hoermann 2009
*/

var J = jQuery.noConflict();

/* when the document is ready */
jQuery(document).ready(function()
{	
	//J(".moretextC").each(function(){J(this).qtip({content: J(this).next("div") })});
	//J(".moretextOR").each(function(){J(this).qtip({content: J(this).next("div") })});
	//J(".moretextOL").each(function(){J(this).qtip({content: J(this).next("div") })});

	//------------------------------------------------------------------
	// Tooltips for the paragraph with class = moretext in the current view
	J(".moretextC").each(function()
	{
		J(this).qtip(
		{
			content: J(this).next("div"),
			position: 
			{ 
				
				corner: { target: "bottomRight", tooltip: "topLeft" } 
			},		
			style: 
			{ 
				width: 185,
				padding: 5,
				background: "#f0f2f0",
				color: "#444444",
				textAlign: "left",
				border: { width: 1, radius: 0, color: "#999" },
				fontSize: 11,
				name: "light",
				tip:
				{
					corner: "leftTop",
					color: "#999",
					size:
					{
						x: 12,
						y: 12
					}
				}			
			},
			show: { effect: "fade" },
			hide: { effect: "fade" }	
		})
	});
	
	//------------------------------------------------------------------
	// Tooltips for the paragraph with class = moretext in the overview
	J(".moretextOR").each(function()
	{
		J(this).qtip(
		{
			content: J(this).next("div"),
			position: { corner: { target: "bottomLeft", tooltip: "topRight" } },
			style: 
			{ 
				width: 240,
				padding: 5,
				background: "#f0f2f0",
				color: "#444444",
				textAlign: "left",
				border: { width: 1, radius: 0, color: "#999" },
				fontSize: 11,
				tip:
				{
					corner: "rightTop",
					color: "#999",
					size:
					{
						x: 12,
						y: 12
					}
				},
				"padding-left": "16px"
				
			},
			show: { effect: "fade" },
			hide: { effect: "fade" }		
		})
	});
	
	//------------------------------------------------------------------
	// Tooltips for the paragraph with class = moretext in the overview
	J(".moretextOL").each(function()
	{
		J(this).qtip(
		{
			content: J(this).next("div"),
			position: { corner: { target: "bottomRight", tooltip: "topLeft" } },
			style: 
			{ 
				width: 240,
				padding: 5,
				background: "#f0f2f0",
				color: "#444444",
				textAlign: "left",
				border: { width: 1, radius: 0, color: "#999" },
				fontSize: 11,
				tip:
				{
					corner: "leftTop",
					color: "#999",
					size:
					{
						x: 12,
						y: 12
					}
				},
				"padding-left": "16px"
			},
			show: { effect: "fade" },
			hide: { effect: "fade" }		
		})
	});


	//------------------------------------------------------------------
	// Header Icon Menu
	J("#headermenu li a").hover
	(
	 	// over
		function()
		{
			// get source image name, and prefix (without extension)
			var iconName = J(this).children("img").attr("src");
			var origin = iconName.split(".png")[0];
			
			// Set source of over image
			//J(this).children("img").attr({src: "" + origin + "Over.png"});
			
			// animate the link
			J(this).animate({width:"195px"}, {queue:false, duration:"normal"});
			
			// animate the span with the text
			J(this).children("span").animate({opacity: "show"}, "fast");			
		},
		// out
		function()
		{
			var iconName = J(this).children("img").attr("src");
			var origin = iconName.split("Over.")[0];
			//J(this).children("img").attr({src: "" + origin + ".png"});
			J(this).animate({width:"45px"}, {queue:false, duration:"normal"});
			J(this).animate("span").animate({opacity:"hide"}, "fast");
		}
	);


	//-------------------------------------------------------------------
	// Cycle header images
	J("#headerimage").cycle({fx:"fade", speed:3500});

	//-------------------------------------------------------------------
	// Tirol Links
	J("#headerlinks a img").hover
	(
	 	// over
		function()
		{
			// show fully
			J(this).animate({opacity: "1"}, "fast");
		},
		// out
		function()
		{
			// set opacity again to 20%
			J(this).animate({opacity: ".2"}, "fast");
		}
	);	
	
	
	//------------------------------------------------------------------
	// News Ticker
	var ticker = J("#ticker");
	
	ticker.children().filter("dt").each(function()
	{
		var dt = J(this);
		var container = J("<div>");
		
		dt.next().appendTo(container);
		dt.prependTo(container);
		container.appendTo(ticker);
	});
	
	ticker.css("overflow", "hidden");
	
	function animator(currentItem)
	{
		var distance = currentItem.height();
		var duration = (distance - Math.abs(parseInt(currentItem.css("marginTop")))) / 0.021;
		currentItem.animate({ marginTop: -distance }, duration, "linear", function() 
		{
			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
			animator(currentItem.parent().children(":first"));
		});
	}
	
	animator(ticker.children(":first"));
	ticker.mouseenter(function() { ticker.children().stop(); });
	ticker.mouseleave(function() { animator(ticker.children(":first")); });		


	//------------------------------------------------------------------
	// SCROLL TO TOP
	J("#toTop").scrollToTop({speed:1000,ease:"easeInOutQuad"});
	
	//------------------------------------------------------------------
	// SROLL Sidebars (leftcol, rightcol)
	
	/*var menuYlocLeft = null;
	var nameLeft = "#leftcol";
	menuYlocLeft = parseInt(J(nameLeft).css("top").substring(0, J(nameLeft).css("top").indexOf("px")));
	J(window).scroll(function() 
	{
		var offset = menuYlocLeft + J(document).scrollTop() + "px";
		J(nameLeft).animate({ top:offset}, {duration:500, queue:false});
	});
	
	var menuYlocRight = null;
	var nameRight = "#rightcol";
	menuYlocRight = parseInt(J(nameRight).css("top").substring(0, J(nameRight).css("top").indexOf("px")));
	J(window).scroll(function() 
	{
		var offset = menuYlocRight + J(document).scrollTop() + "px";
		J(nameRight).animate({ top:offset}, {duration:500, queue:false});
	});
	*/
	
	//------------------------------------------------------------------
	//Hyphenator.run();
	
	//------------------------------------------------------------------
	// Main Menu	
	J("ul.mainnav li a").hover
	(
	 	// 
	 	function() 
		{ 
			J(this).addClass("active");
			//Drop down the subnav on click
			J(this).parent().find("ul.subnav").stop().slideDown("3000").show("2500", function()
			{
				J(this).height("auto");
			}); 

			//When the mouse hovers out of the subnav, move it back up
			J(this).parent().hover
			(
			 	// over
		 		function() {}, 
				// out
				function()
				{	
					J(this).find("a").removeClass("active");
					J(this).parent().find("ul.subnav").stop().slideUp("2500")
				}
			);

		//Following events are applied to the trigger (Hover events for the trigger)
		}
	)
	.hover
	(
	 	// over
	 	function() { J(this).addClass("subhover"); }, 
		// out
		function(){	J(this).removeClass("subhover"); }
	);
});
