if(browser() > 8) document.addEventListener('DOMContentLoaded', loaded, false);  


var myScroll;

function loaded() {
	myScroll = new iScroll('bottom', { scrollbarColor: 'rgba(20,0,0,0)', checkDOMChanges: false, bounce: true, momentum: true });
	var p = jQuery(".news-list-container .news-current");
	var startseite = jQuery('body').hasClass('intro');
	if(p.offset() != null && !startseite) myScroll.scrollTo(180-p.offset().left,0,0);
}


jQuery(document).ready(function(){
	if(browser() <= 8){
		jQuery("#wrapper .bottom").css("overflow-x", "auto");
	}
	
	
	
	if(plattform() == "iPad"){
		jQuery("#popupinhalt").css("height", "580px");
		jQuery("#popupVideo .overlayEnd").css("display", "block");
		jQuery("#popupVideo .box1, #popupVideo .box2, #popupVideo .box3").css("opacity", "0.3");
		jQuery("#popupVideo .overlayEnd").css("top", "513px");
		jQuery("#popupVideo .overlayEnd").css("text-align", "left");
		jQuery("#popupVideo .overlayEnd a").css("float", "left");
		jQuery("#popupVideo .overlayEnd a").css("width", "238px");
		jQuery("#popupVideo .overlayEnd a").css("margin-right", "10px");
		jQuery("#popupVideo .overlayEnd .box3 a").css("margin-right", "0px");
	}
	
	
	

	var newsActive = jQuery(".news-list-container .news-current").length;
	if(newsActive == 0){
		jQuery(".news-list-container .news-item-box").first().addClass("news-current");
	}
	
	//alert("position left: "+p.offset().left);
	var num = (jQuery(".news-list-item").length*200)+jQuery('.bottom').width();
	jQuery(".bottom .inner").css("width",num);
	if(jQuery(".intro-text").width() != null){
		var num = (jQuery(".news-list-item").length*200)+jQuery('.bottom').width();
	}else{
		var num = (jQuery(".news-list-item").length*200)+jQuery('.bottom').width();
	}
	jQuery(".news-list-container").css("width",num);
	
	jQuery('#advertisement_frog').jsMovie({
        sequence : "Anim-frog##.jpg",    //the #### will be replaced with 0001,0002,0003,É
        folder   : "media/anims/",       //this is the path where the script can find the image sequence
        from     : 1,               //the #### will start to replace with 0001
        to       : 29,              //the #### will start to replace with 0040
        width    : 783,             //the advertisement container will be resized to a width of 320px
        height   : 999,             //the advertisement container will be resized to a height of 150px
        repeat	 : false,
        showPreLoader : false,       //we do want to see a preloader animation
        playOnLoad : false,         //we don't want to have the movie play after the images have been loaded automatically
        // the preloader animation is located in the folder "img/loader.png"
        // it is a 4x4 image matrix with each image of 40px by 40px
        loader   : {path:"media/loader.png",height:40,width:40,rows:4,columns:4}
        
    });
	
	jQuery('#advertisement_frog').jsMovie("addClip","Frog1",1,29,2000);
	//jQuery('#advertisement_frog').jsMovie("addClip","Frog3",15,24);
	
	//jQuery('#advertisement_frog').jsMovie('ended', frogEnded);
	
	
	jQuery('#advertisement').jsMovie({
        sequence : "Anim-Start##.jpg",    //the #### will be replaced with 0001,0002,0003,É
        folder   : "media/anims/",       //this is the path where the script can find the image sequence
        from     : 1,               //the #### will start to replace with 0001
        to       : 4,              //the #### will start to replace with 0040
        width    : 789,             //the advertisement container will be resized to a width of 320px
        height   : 511,             //the advertisement container will be resized to a height of 150px
        repeat	 : false,
        showPreLoader : true,       //we do want to see a preloader animation
        playOnLoad : false,         //we don't want to have the movie play after the images have been loaded automatically
        // the preloader animation is located in the folder "img/loader.png"
        // it is a 4x4 image matrix with each image of 40px by 40px
        loader   : {path:"media/loader.png",height:40,width:40,rows:4,columns:4}
        
    });
    
    jQuery('#advertisement').jsMovie("addClip","Hello",1,4,2000);
    
    var introDone = false;
    var firstTime = false;
    
    jQuery("#dartFroschButton").hover(
		function () {
    		playFrogSound();
    		jQuery("#advertisement_frog").css("display", "block");
    		jQuery("#advertisement_frog").css("opacity", "1");
    		jQuery("#advertisement_frog").jsMovie("stop");
    		jQuery("#advertisement_frog").jsMovie("gotoFrame", 0);
  		}, 
  		function () {
  			jQuery("#advertisement_frog").css("display", "none");
    		jQuery("#advertisement_frog").css("opacity", "0");
  		}
	);
	
	jQuery("#dartFroschButton").mouseup(
		function () {
			jQuery("#advertisement_frog").css("display", "block");
    		jQuery("#advertisement_frog").css("opacity", "1");
    		jQuery("#advertisement_frog").jsMovie("stop");
    		jQuery("#advertisement_frog").jsMovie("gotoFrame", 0);
			showFrog();
			//alert(jQuery("#dartFroschButton").data("events"))
		} 
	);
	/*jQuery("#dartFroschButton").bind('playing', function() {
	  alert('User clicked on "foo."');
	});*/
	
	//var frogNum = 0;
	
	jQuery("#advertisement_frog").bind("ended", function(){
		jQuery("#advertisement_frog").css("display", "none");
    	jQuery("#advertisement_frog").css("opacity", "0");
	});
	
	
    
    
    jQuery("#advertisement").hover(
		function () {
    		if(introDone == true){
    			if(firstTime){
    				firstTime = false;
    			}else{
    				jQuery("#advertisement").jsMovie("option","playBackwards",false);
    				//jQuery("#advertisement").jsMovie("playClip","Hello");
    				jQuery("#advertisement").jsMovie("playClips");
    			}
  			}
  		}, 
  		function () {
  			if(introDone == true){
  				jQuery("#advertisement").jsMovie("option","playBackwards",true);
    			jQuery("#advertisement").jsMovie("playClips");
  			}
  		}
	);
	
	jQuery("#advertisement, #dartMovieButton").mouseup(
		function () {
			if(plattform() == "iPad"){
				setTimeout("showPopup()", 300);
			}else{
				showPopup();
			}
			
		}
	);
	
	
	centerBild();
	
	jQuery("#advertisement, #advertisement_bg, #advertisement_frog").css('left', 0);

	jQuery("#dartMovieButton").css('bottom', '-52px');
	jQuery("#dartFroschButton").css('bottom', '-52px');
	if(!window.location.hash) {	
		
		
		jQuery("#wrapper .top .logo").css('position', 'relative');
		jQuery("#wrapper .top .logo").css('z-index', '160');
		jQuery("#wrapper .top .menu").css('position', 'relative');
		jQuery("#wrapper .top .menu").css('z-index', '150');
		//jQuery("#wrapper .top .menu").css('top', -22);
		jQuery("#advertisement").css('opacity', 0);
		jQuery("#wrapper .bottom").css('bottom', -280);
		jQuery("#wrapper .top").css('top', -71);
		
		jQuery("#advertisement_bg").css('display', "block");
		  jQuery("#advertisement_bg").animate({
		   	opacity: 1
		  }, 500, function() { 
		 		introDone = true; 
		  	jQuery("#advertisement").css('display', "block");
		  	jQuery("#advertisement").animate({
		    	opacity: 1
		  	}, 1000, function() {  
		  		
		  		jQuery("#wrapper .top").animate({
	    			top: 0
	  			}, 1000, function() { });
			
				
				jQuery("#wrapper .bottom").animate({
	    			bottom: 0
	  			}, 1500, function() { 
	  				jQuery("#dartMovieButton").animate({
		    			bottom: 255
		  			}, 700, function() { 
		  				jQuery("#dartFroschButton").animate({
			    			bottom: 255
			  			}, 700, function() { });
		  			});
	  			});
		  				  	
		  	});
	  	});
			 
		
		
	}
	else {
		
		jQuery("#advertisement_bg").css('display', "block");
	  	jQuery("#advertisement_bg").animate({
	    	opacity: 1
	  	}, 500, function() { 
	  		jQuery("#dartMovieButton").animate({
		    	bottom: 255
		  	}, 700, function() { 
		  		jQuery("#dartFroschButton").animate({
			    	bottom: 255
			  	}, 700, function() { });
		  	});
	  	
	  		introDone = true; 
	  		jQuery("#advertisement").css('display', "block");
		  	jQuery("#advertisement").animate({
		    	opacity: 1
		  	}, 1000, function() { });
	  	});
	}	
	
	jQuery("#sexybookmarks .external").hover(function(){
        
			 var fill = jQuery(this).find("img:first").attr("src");		 
			 var length = fill.length;
			 length = length-4;     //".png"			 
			 var split = fill.slice(0, length);
			 var fill_hover = split + "_hover.png";			 	
			 jQuery(this).find("img:first").attr("src", fill_hover);
		}, function(){
		  var fill = jQuery(this).find("img:first").attr("src");
			 var length = fill.length-10;   //"_hover.png"
			 var split = fill.slice(0, length);
			 var fill_hover = split + ".png";
			 jQuery(this).find("img:first").attr("src", fill_hover);
		}
	);

});

jQuery(window).resize(function() {
	centerBild();
});





function centerBild(){
 	var bildConHeight = jQuery("body").height() - 71 - 240;
	var bildConDiff = bildConHeight - jQuery('#advertisement').height() ;
	
	var newYPos = 71+(bildConDiff/2);
	
	var bgNewYPos = newYPos-(jQuery('#advertisement').height()/2)+6;
	
	jQuery("#advertisement").css("top", newYPos);
	jQuery("#advertisement_frog").css("top", newYPos-244);
	
	jQuery("#advertisement_bg").css("top", bgNewYPos);
	jQuery("#advertisement_bg").css("height", jQuery("body").height()-bgNewYPos);
}

function showFrog(){
	
	//jQuery("#advertisement_frog").jsMovie("playClip", "Frog1");
	jQuery("#advertisement_frog").jsMovie("playClips");
}

function frogEnded(){
	alert("hallo melanie!")
}

function playFrogSound(){
	if(browser() > 8){
		var mySound = document.getElementById("frog_audio");
	 	mySound.play();
	}

}

