jQuery(function(){ // start jQuery
	
	// country switcher
	jQuery(".selectCountry").click(function(){
		jQuery(this).toggleClass("selectClicked");
		//jQuery("#countrySwitch").fadeToggle("fast");
		if(jQuery(this).hasClass("selectClicked")){
			jQuery("#countrySwitch").fadeIn("medium");
		} else {
			jQuery("#countrySwitch").fadeOut("fast");
		}
		return false;
	});
	
	// tab system //
	var mainTab = jQuery(".primaryTabs li a");
	var subTabTrig = jQuery(".subTabs li a");
	var fileGroup = jQuery(".tabContentWrap");
	var fileSubGroup = jQuery(".tabContentWrap .tabContent");
	
	fileGroup.children("div").addClass("tabContent");
	
	jQuery(mainTab).click(function(){  		
		var num = (mainTab.index(this));
		jQuery(mainTab).removeClass("active");
		jQuery(mainTab[num]).addClass("active");
		
		jQuery(fileGroup).removeClass("show").addClass("hide");
		jQuery(fileGroup[num]).removeClass("hide").addClass("show");
		
		
//		jQuery(fileSubGroup).removeClass("show").addClass("hide");
//		jQuery(".tabContentWrap div:nth-child(2)").removeClass("hide").addClass("show");
//		
//		jQuery(subTabTrig).removeClass("active");
//		jQuery(".tabContentWrap li:nth-child(1) a:nth-child(1)").addClass("active");
		//alert("no");
		
		return false;
		
	});
	
	jQuery(subTabTrig).click(function(){
				
		var num = (subTabTrig.index(this));
		jQuery(subTabTrig).removeClass("active");
		jQuery(subTabTrig[num]).addClass("active");
		
		jQuery(fileSubGroup).removeClass("show").addClass("hide");
		jQuery(fileSubGroup[num]).removeClass("hide").addClass("show");
		
	
		return false;
	});	   
		   
	// pngFix //
	jQuery("#logoMain, #utilityNav, .podWrap, #subHeader").pngFix(); // parent element of transparent png
	
	// Home Slider
	jQuery("#homeSlider").anythingSlider({
		startStopped    : false, // If autoPlay is on, this can force it to start stopped
		autoPlayLocked  : true,  // If true, user changing slides will not stop the slideshow
		resumeDelay     : 7000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
		delay           : 7000  // How long between slideshow transitions in AutoPlay mode (in milliseconds)
	});
		
	// COLLAPSIBLE CONTENT
	jQuery(".collapseWrap ul:first").collapseContent({
		slideSpeed: 250,
		easingAnim: 'swing', // refer to names in jquery.easing.1.3.js
		showFirst: true,
		showOnlyOne: true
	});

	// background position plug in //
	jQuery.extend(jQuery.fx.step,{
		backgroundPosition: function(fx){
			if (fx.state === 0 && typeof fx.end == 'string') {
				var start = jQuery.curCSS(fx.elem,'backgroundPosition');
				start = toArray(start);
				fx.start = [start[0],start[2]];
				var end = toArray(fx.end);
				fx.end = [end[0],end[2]];
				fx.unit = [end[1],end[3]];
			}
			
			var nowPosX = [];
			nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
			fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
			
			function toArray(strg){
				strg = strg.replace(/left|top/g,'0px');
				strg = strg.replace(/right|bottom/g,'100%');
				strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
				var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
			}
		}
	});
	
	var dateCET = new Date(); // Central European Time is GMT +1
	var hours = parseInt(dateCET.getHours());
	
	if ((hours >= 0 && hours <= 6) || (hours >= 19 && hours <= 24)) {
		jQuery('body').addClass('bgNight')
	}
	if (hours > 6 && hours <= 9) {
		jQuery('body').addClass('bgDawn')
	}
	if (hours > 9 && hours <= 17) {
		jQuery('body').addClass('bgDay')
	}
	if (hours > 17 && hours < 19) {
		jQuery('body').addClass('bgDusk')
	}

	
	var dayClouds = (jQuery('body').hasClass ('bgDay')) ? true : false;
	var dawnClouds = (jQuery('body').hasClass ('bgDawn')) ? true : false;
	var noClouds = ((jQuery('body').hasClass ('bgDusk')) || (jQuery('body').hasClass ('bgNight'))) ? true : false;
	
	if (dayClouds) {
		var whatClouds = "dayClouds";
	}
	else if (dawnClouds){
		var whatClouds = "dawnClouds";
	}
	else if (noClouds){
		var whatClouds = "noClouds";
	} 
	
	var whatCloudsClass = "." + whatClouds;
		
	jQuery("#backgroundClouds").children().addClass(whatClouds);
			
	// background positioning - daytime //
	jQuery(whatCloudsClass).find('.cloud1').css({backgroundPosition: '0px 0px'});
	jQuery(whatCloudsClass).find('.cloud2').css({backgroundPosition: '0px 0px'});
	jQuery(whatCloudsClass).find('.cloud3').css({backgroundPosition: '0px 0px'});
	jQuery(whatCloudsClass).find('.cloud4').css({backgroundPosition: '0px 0px'});
	
	
	jQuery(whatCloudsClass).find('.cloud1').animate({
		backgroundPosition:"(-900px 0)"
	}, 480000, 'linear');
	
	jQuery(whatCloudsClass).find('.cloud2').animate({
		backgroundPosition:"(-100px 0)"
	}, 120000, 'linear');
	
	jQuery(whatCloudsClass).find('.cloud3').animate({
		backgroundPosition:"(-900px 0)"
	}, 480000, 'linear');
	
	jQuery(whatCloudsClass).find('.cloud4').animate({
		backgroundPosition:"(-4000px 0)"
	}, 480000, 'linear');
	
	
//	// speed in milliseconds
//    var scrollSpeed = 70;
//    // set the direction
//    var direction = 'h';
//    // set the default position
//    var current = 0;
//    function bgscroll(){
//        // 1 pixel row at a time
//        current -= .1;
//        // move the background with backgrond-position css properties
//        jQuery('div.clouds').css("backgroundPosition", (direction == 'h') ? current+"px 0" : "0 " + current+"px");
//    }
// 
//    //Calls the scrolling function repeatedly
//    var init = setInterval("bgscroll()", scrollSpeed);  
//	
//	jQuery('.cloud1').bgscroll({scrollSpeed:13000 , direction:'h' });
//    jQuery('.cloud2').bgscroll({scrollSpeed:8300 , direction:'h' });
//    jQuery('.cloud3').bgscroll({scrollSpeed:5700 , direction:'h' });
//    jQuery('.cloud4').bgscroll({scrollSpeed:150 , direction:'h' });
	
	//alert(whatClouds);
		
	//Examples of how to assign the ColorBox event to elements
	
	//jQuery("a[rel='example1']").colorbox();
	//jQuery("a[rel='example2']").colorbox({transition:"fade"});
	//jQuery("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	//jQuery("a[rel='example4']").colorbox({slideshow:true});
	//jQuery(".example5").colorbox();
	jQuery(".iframeModal").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	jQuery(".iframeModalHD").colorbox({iframe:true, innerWidth:640, innerHeight:360});
	jQuery(".speedTest").colorbox({iframe:true, innerWidth:425, innerHeight:562});
	//jQuery(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	//jQuery(".example8").colorbox({width:"50%", inline:true, opacity:.5, href:"#inline_example1"});
	//jQuery(".example9").colorbox({
		//onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		//onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		//onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		//onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		//onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	//});
	//Example of preserving a JavaScript event for inline calls.
	jQuery("#click").click(function(){ 
		jQuery('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
	
	jQuery(".toggleContainer").hide();

	jQuery(".trigger").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});
	
	jQuery(".custom-aboutus").parents(".pad").css({paddingBottom : 0}); 
	
	jQuery(".my-account").siblings(".st_sharethis_button").hide();

    stLight.options({
       publisher:'905a98d4-2637-4dfd-aa65-4ef4ef3e1f8f',
       popup: false,
       onhover: false
    });

	// photo gallery
	//jQuery('#flickr_div').flickrGallery('72157626140568789','551ea5269b6464e277a7f4fbddd55303');
	//jQuery("#flickr_div").flickrGallery('72157622617592496',"5dae9b03980e10344afd862c38843c38");

});

//(function() {
//    jQuery.fn.bgscroll = jQuery.fn.bgScroll = function( options ) {
//         
//        if( !this.length ) return this;
//        if( !options ) options = {};
//        if( !window.scrollElements ) window.scrollElements = {};
//         
//        for( var i = 0; i < this.length; i++ ) {
//             
//            var allowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
//            var randomId = '';
//            for( var l = 0; l < 5; l++ ) randomId += allowedChars.charAt( Math.floor( Math.random() * allowedChars.length ) );
//             
//                this[ i ].current = 0;
//                this[ i ].scrollSpeed = options.scrollSpeed ? options.scrollSpeed : 70;
//                this[ i ].direction = options.direction ? options.direction : 'h';
//                window.scrollElements[ randomId ] = this[ i ];
//                 
//                eval( 'window[randomId]=function(){var axis=0;var e=window.scrollElements.' + randomId + ';e.current -= 1;if (e.direction == "h") axis = e.current + "px 0";else if (e.direction == "v") axis = "0 " + e.current + "px";else if (e.direction == "d") axis = e.current + "px " + e.current + "px";jQuery( e ).css("background-position", axis);}' );
//                                                          
//                setInterval( 'window.' + randomId + '()', options.scrollSpeed ? options.scrollSpeed : 70 );
//            }
//             
//            return this;
//        }
//})(jQuery); 



