//
var $domain = "http://redroo.de/";
var $flashversion = "9.0.124.0";
//
var $j = jQuery.noConflict();
$j(document).ready(function() 
{
	/* helper methods */
	function trace()
	{
		if (('console' in window) && ('firebug' in console)) 
		{
			//console.trace();
			console.log(arguments);
		}
	}
	// Fixign PNG issues in IE6
	if ($j.browser.msie && $j.browser.version == 6) 
	{
	   	//$j.ifixpng('../../img/ie6/pixel.gif');
	   	//$j('img[@src$=.png]').ifixpng();
		//$j('#Wrapper').ifixpng();
	}
	// Slideshow start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	if ($j('#SlideShow').length == 1)
	{
		var flashvars = {};
		flashvars.file = "swf/slideshow/playlist.php";
		flashvars.domain = $domain;
		flashvars.backgroundImage = "img/content/page/green2.jpg";
		flashvars.overstretch = "false";
		flashvars.transition = "fade";
		flashvars.linkfromdisplay = "false";
		flashvars.usekeys = "false";
		flashvars.shownavigation = "false";
		flashvars.overstretch = "none";
		flashvars.autostart = "true";
		flashvars.repeat = "true";
		flashvars.rotatetime = "2";
		flashvars.shuffle = "true";
		flashvars.debugging = 'false';
		var params = {};
		params.menu = "false";
		params.quality = "best";
		params.wmode = "";
		params.allowscriptaccess = "sameDomain";
		params.seamlesstabbing = "true";
		var attributes = {};
		attributes.id = "slideshow";
		attributes.name = "slideshow";
		swfobject.embedSWF(
			"swf/slideshow/slideshow.swf", 
			"SlideShow", 
			"950", 
			"500", 
			$flashversion, 
			"swf/slideshow/expressInstall.swf", 
			flashvars, 
			params, 
			attributes
		);
	}
	//*/
	// Slideshow end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Navi start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function addNaviClasses()
	{
		jQuery.each($j('.navItem a span'), function(i, val) 
		{
			var s = $j(val).text();
			var f = s.toLowerCase().replace(/ /gi, '_');
			$j(val).after ('<img id="' + f + '" src="' + $domain + 'img/navi/' + f + '.png" />');
			$j(val).remove();
		});
		jQuery.each($j('.navItem.active span'), function(i, val) 
		{
			var s = $j(val).text();
			var f = s.toLowerCase().replace(/ /gi, '_');
			$j(val).after ('<img id="' + f + '" src="' + $domain + 'img/navi/' + f + '_OVER.png" />');
			$j(val).remove();
		});
		$j('.navItem a img').hover(
			function () 
			{
				var s = $j(this).attr('src');
				$j(this).attr('src', s.substring (0, s.lastIndexOf('.')) + '_OVER.png');
				$j(this).addClass('hover');
			}, 
			function () {
				var s = $j(this).attr('src');
				$j(this).attr('src', s.substring (0, s.lastIndexOf('_')) + '.png');
				$j(this).removeClass('hover');
			}
		)
		// catch key-events:
		$j('.navItem a img').blur(
			function ()
			{
				console.log(this);
			}
		);
		function triggerNaviItemHover()
		{
			$j('.navItem a img.hover').trigger('mouseout');
			$j(this).children().trigger('mouseover');
		}
		$j(window).keydown(
			function(event){
				if(event.keyCode == 9) // the Tab-Key
				{
					triggerNaviItemHover();
				}
			}
		);
  	}
	addNaviClasses();
	// Navi end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Image Replacement start 
	function replaceHeadlines ()
	{
		jQuery.each($j('.ir'), function(i, val) 
		{
			var s = $j(val).text();
			var f = s.toLowerCase().replace(/ /gi, '_');
			var img = "url('" + $domain + 'img/content/headlines/' + f + '.png' + "') no-repeat";
			$j(val).css({
				"background":img
			});
		});
	}
	replaceHeadlines ();
	// Image Replacement end
	// apply teaser start
	function applyTeaserStyle ()
	{
		$j('#Teaser img')
		.css({opacity:'0.4'})
		.hover (
		function ()
		{
			$j(this).animate(
				{
					opacity:'1'
				},
				{ 
					queue:true, 
					duration:400 
				}
			)
		},
		function ()
		{
			$j(this).animate(
				{
					opacity:'0.4'
				},
				{ 
					queue:true, 
					duration:240 
				}
			)
		});
	}
	applyTeaserStyle ();
	// apply teaser end
	// apply language-selector-style
	function applyLangSelStyle ()
	{
		$j('img.lang').css({
			opacity:'.4',
			cursor:'pointer'
		})
		$j('img.lang.active').css({
			cursor:'inherit',
			opacity:'1'
		})
		$j('img.lang').not('img.lang.active').hover(
			function ()
			{
				$j(this).animate(
					{
						opacity:'1'
					},
					{ 
						queue:true, 
						duration:400 
					}
				)
			},
			function ()
			{
				$j(this).animate(
					{
						opacity:'.4'
					},
					{ 
						queue:true, 
						duration:200 
					}
				)
			}
		)
	}
	applyLangSelStyle ();
	// apply language-selector-style end
	// apply form toggle start
	function applyFormToggle ()
	{
		$j('form .hide div').hide();
		$j('form .toggle legend').bind('click', function()
		{
			if (!$j(this).hasClass('open'))
			{
				$j(this).parent().find('div').fadeIn();
			}
			else
			{
				$j(this).parent().find('div').fadeOut();
			}
			$j(this).toggleClass("open");
		});
		var lang = $j.cookie('redroo_lang');
		if (lang == 'en')
		{
			var t = "(show/hide)";
		}
		else
		{
			var t = "(ein-/ausblenden)";
		}
		// 
		// 
		$j('form .toggle legend').html($j('form .toggle legend').text() + '<span> ' + t + '</span>');
	}
	applyFormToggle ();
	// apply form toggle end
	// unclutter email links start
	function unclutterEMailLinks ()
	{
		jQuery.each($j('a.email'), function(i, val) 
		{
			var s = $j(val).attr('href');
			var a = s.replace(/\[at\]/i, "@").replace(/\[dot\]/i, ".");
			$j(val).attr('href', a);
			s = $j(val).text();
			var t = s.replace(/\[at\]/i, "@").replace(/\[dot\]/i, ".");
			
			$j(val).text (t);
		});
	};
	unclutterEMailLinks ();
	// unclutter email links end
	// apply Polytex 
	function applyPolytex ()
	{
		// adding needed CSS:
		$j('.slider ul').data('width', 0);
		
		$j.each ($j('.previews img'), function (i, val)
		{
			$j(this)
				.css('cursor', 'pointer')
				.data('nr', i)
				.data('boundTo', $j('.slider img:eq(' + i + ')'))
				.bind('click', function ()
				{
					
					var imagecount = $j('.slider img').length;
					var boundTo = $j(this).data('boundTo');
					$j('.slider ul')
						.animate({left:-$j(this).data('nr')*boundTo.width()}, 1200, "easeOutElastic");
				});
		});
		//
		$j.each($j('.slider img'), function (i, val)
		{
			var w = $j(this).width();
			var ul = $j(this).parent().parent();
			if (w == 0) 
				w = 300;1
			ul.data('width', ul.data('width') + w);
			$j(".slider ul").css('width', ul.data('width'));
			$j(this)
				.data('nr', i)
				.data('boundTo', $j('.slider img:eq(' + i + ')'))
				.data('width', w);
		});		
		$j('.slider li').css('float', 'left');
		//*
		$j('.slider ul').css({
			position: 'absolute',
			left:0
		});
		$j('.slider, .slider ul, .inner').css('overflow', 'hidden');
		//
	}
	applyPolytex ();
	// apply Polytex end
	// apply PopupLinks
	function applyPopupLinks ()
	{
		$j('a.popup').bind('click', function ()
		{
			var url = $j(this).attr('href');
			var fenster = window.open(url, "halbro", "width=900,height=600,status=yes,scrollbars=yes,resizable=yes");
 			fenster.focus();
			return false;
		});
	}
	applyPopupLinks ();
	// apply PopupLinks
	
	// add columns for old browsers:
	if ($j.columnize != undefined) 
	{
  	if ($j.browser.opera || $j.browser.msie) {
  		$j('.columns').columnize({
  			columns: 2
  		});
  	}
  }
});







