$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


$(function()
{
	$('.scroll-pane').jScrollPane();
});

function init_microtrend()
{

	$(".trend_link a").click(function(event){
		event.preventDefault();

		url = $(this).attr("href");
		$.ajax({
			   url: url
			,  cache: true
			,  success: function(msg){
				$.blockUI({
					  message: msg
			 		, css: {
						  top:  ($(window).height() - 480) /2 + 'px'
						, left: ($(window).width() - 700) /2 + 'px'
						, width: '700px'
			 		}
				});

				$("#micro-trend #close").attr("title","Click to close").click($.unblockUI);
				
				$('.blockOverlay').attr("title","Click to close").click($.unblockUI);
			} // success
		});
	});	

	$(".trend_image a").click(function(event){
		event.preventDefault();

		url = $(this).attr("href");
		$.ajax({
			   url: url
			,  cache: true
			,  success: function(msg){
				$.blockUI({
					  message: msg
			 		, css: {
						  top:  ($(window).height() - 480) /2 + 'px'
						, left: ($(window).width() - 700) /2 + 'px'
						, width: '700px'
			 		}
				});

				$("#micro-trend #close").attr("title","Click to close").click($.unblockUI);
				
				$('.blockOverlay').attr("title","Click to close").click($.unblockUI);
			} // success
		});
	});	


}

(function($){ 
  jQuery.fn.glimmer = function()
  { 
	this.each(function() {

		var t = $(this);
		t.do_glimmer = function() {
			t.delay(Math.random()*3000+2000).animate({opacity:Math.random()*0.5+0.5}, Math.random()*100+100, null, function() {
				$(this).animate({opacity: 1.0}, Math.random()+100, null, t.do_glimmer);
			});
		};
		t.do_glimmer();	
	}
	);
  };
})(jQuery);




var page_actions = {
	"page32": function() {
/*
		i = 0;
		$(".star").each(function() {
			t = $(this);
			t.hide();
			delay = i * 1000 + 1000;
			t.delay(delay).fadeIn("slow");
			t.glimmer();
			i++;
		});
*/
		
		$('.inline-gallery ul').cycle({
		  fx:       'fade'
	    , pager:    '.inline-gallery .pager'
	    , easing:   'easeInOutQuart'
	    , speed:    1300
	    , timeout:  3000
	    , delay:    1000
		, height: 300
	    , cleartypeNoBg: true
	 	, pauseOnPagerHover: true 
		, allowPagerClickBubble: true
       });
		
		
	},
	"page119": function()
	{
		// hide delivery address when not needed
		if(!$("#deliveryaddress_other:checked").val())
		{
			$("#deliveryaddress_wrap").hide();
			$("#billing").hide();
		} else {
			$("#billinganddelivery").hide();
			$("#billing").show();
		}

		// toggle delivery address
		$("#deliveryaddress_other").click(function() {

			if(this.checked) {
				$("#deliveryaddress_wrap").slideDown();
				$("#billinganddelivery").hide();
				$("#billing").show();				
			} else {
				$("#deliveryaddress_wrap").slideUp();
				
				$("input", "#deliveryaddress_wrap")
				 .val("")				
				 .removeAttr("checked")
				 .removeAttr("selected");

				// remove error classes (twice beacuase of double error in zip,city or street,no)
				$(".formrow",'#deliveryaddress_wrap').removeClass("error").removeClass("error");

				$("#billinganddelivery").show();
				$("#billing").hide();				
			}
		});		
	},
	"page121": function() {
		page_actions["page119"]();
	},
    "page26": function()
    {
    /*
        $(".news-single-img a").each(function(){
            $(this)[0].onclick = function(){return false};
        });
        $(".news-single-img a").click(function(event)
        {
            event.preventDefault();
            
        });
	*/        

    },
    
	'page93': function()
	{
		// shortcut
		industries = $("#infos_branchen");
		industrie_reports = $("#branchenreports");
		
		// check for qs value "interes" to precheck items
		// must be name of checkbox
		check = $.getUrlVar('interest');
		cb = $("#"+escape(check));

		if(cb.length)
		{
			cb.attr("checked", "true");
			industries.attr("checked", $("#branchenreports input").is(':checked'));
		}
		
		// hide sub industries only when industries not checked
		industrie_reports.toggle(industries.attr("checked"));	
		
		industries.click(function(){
			state = $(this).attr("checked");
			if(!state)
			{ // clear subindustries on unselect industries
			  $("#branchenreports input").attr("checked", false);
			}
			$("#branchenreports").toggle(state);
		});
	},
	'page30': function()
	{
		min_opacity = 0.7;
		
		// prepare fading team images
		$(".staff_image img")
			.mouseout(function(){$(this).fadeTo("fast", 1.0)})
			.mouseover(function(){$(this).fadeTo("slow", min_opacity)});
		
	},
    "page20": function()
    {
		$('#cycleContainer').cycle({
		  fx:       'scrollHorz' 
		, speed:    'fast' 
	    , timeout:  0 
	    , pager:    '#cyclenav'
	    , easing:   'easeInOutQuart'
	    , speed:    600
	    , timeout:  6000
	    , delay:    1000
	    , pause:    true
	    , cleartypeNoBg: true
	 	, pauseOnPagerHover: true 
		, allowPagerClickBubble: true
       });

		init_microtrend();
    
    },  
    "page38": function()
    {
		$('#cycleContainer').cycle({
		  fx:       'scrollHorz' 
		, speed:    'fast' 
	    , timeout:  0 
	    , pager:    '#cyclenav'
	    , easing:   'easeInOutQuart'
	    , speed:    600
	    , timeout:  6000
	    , delay:    1000
	    , pause:    true
	    , cleartypeNoBg: true
	 	, pauseOnPagerHover: true 
		, allowPagerClickBubble: true
       });

		init_microtrend();
    
    },    
	"page5": function() {
		$('#cycleContainer').cycle({
			  fx:       'scrollHorz' 
			, speed:    'fast' 
		    , timeout:  0 
		    , pager:    '#cyclenav'
		    , easing:   'easeInOutQuart'
		    , speed:    600
		    , timeout:  6000
		    , delay:    1000
		    , pause:    true
		    , cleartypeNoBg: true
		 	, pauseOnPagerHover: true 
			, allowPagerClickBubble: true
       });

		init_microtrend();


       // embedding of video player
        var flashvars = {
              file: "/fileadmin/video/teaser201001.mp4"
            , stretching: "fill"
            , autostart: true
		};

		if(typeof(LANG_EN) != "undefined")
		{
			flashvars["captions.file"] = "/fileadmin/video/caption.xml";
			flashvars["plugins"] = "captions";
		}


        var params = {
              allowfullscreen: "true"
        };
        
        var attributes = {
            id: "video_teaser_wrap",
            name: "video_teaser_wrap"
        };

       
       // on click
       $("#frontpage_video").click(function(){
        swfobject.embedSWF("/fileadmin/swf/player.swf", "video_teaser_wrap", "485", "300", "9.0.0", "/fileadmin/swf/expressInstall.swf", flashvars, params, attributes);
       });
       
	}
};

$(document).ready(function(){
	body_id = document.body.id;
	if(page_actions[body_id])
	{
		page_actions[body_id]();
	}
	
	// global stuff
	// prepare ajax links
	$(".memberLink").click(function(event){
		event.preventDefault();
		url = $(this).attr("href");
		$.ajax({
			   url: url
			,  cache: true
			,  success: function(msg){
				$.blockUI({
					  message: msg
					, css: {
						  width: "430px"
						, top:  ($(window).height() - 430) / 2 + 'px'
						, left: ($(window).width() - 430) / 2 + 'px'
						
					}
				});
                   
				$("#stuff #close").attr("title","Click to close").click($.unblockUI);
				$('.blockOverlay').attr("title","Click to close").click($.unblockUI);
				$('.scroll-pane').jScrollPane();
			}
		});
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_square'});	
	
});

