$(document).ready(function() {
	$('#events').tinyscrollbar();
	
	$('div#navigation div.wrapper ul li.home').live("click", function(){
		$('html,body').stop().animate({
					scrollTop: $("#content").offset().top
					},{
					queue: false,
					duration: 1500,
					easing:'swing'
				});
	});
	$('div#navigation div.wrapper ul li.news').live("click", function(){
		$('html,body').stop().animate({
					scrollTop: $("#content_news").offset().top
					},{
					queue: false,
					duration: 1500,
					easing:'swing'
				});
	});
	$('div#navigation div.wrapper ul li.band').live("click", function(){
		$('html,body').stop().animate({
					scrollTop: $("#content_band").offset().top
					},{
					queue: false,
					duration: 1500,
					easing:'swing'
				});
	});
	$('div#navigation div.wrapper ul li.contact').live("click", function(){
		$('html,body').stop().animate({
					scrollTop: $("#content_contact").offset().top
					},{
					queue: false,
					duration: 1500,
					easing:'swing'
				});
	});
	$('div#navigation div.wrapper ul li.shop').live("click", function(){
		window.open('http://www.voices-of-destiny.com/shop/');
	});
	
	
	
	if($(window).height() <= "600" || $(window).width() <= "1024"){
				smallscreen();
			}
			else
			{
				resize_bg("#content div.fullscreen img");
				resize_bg("#content_news div.fullscreen img");
				resize_bg("#content_band ul li img");
			}
	
	$("#socialmedia div#visit").css({opacity: "0"});
	$("div#text").css({opacity: "0"});
	
	$("#content div.fullscreen img").load(function(){
		resize_bg("#content div.fullscreen img");
	})
	$("#content_news div.fullscreen img").load(function(){
		resize_bg("#content_news div.fullscreen img");
	})
	$("#content_band div.fullscreen img").load(function(){
		resize_bg("#content_band ul li img");
	})
	$(window).resize(function(){
			if($(window).height() <= "600" || $(window).width() <= "1024"){
				smallscreen();
			}
			else
			{
				resize_bg("#content div.fullscreen img");
				resize_bg("#content_news div.fullscreen img");
				resize_bg("#content_band ul li img");
			}
			var middle = $(window).width()/2;
			mousefollow(middle);
	})
	function resize_bg(element){
		var resize_img = $(element);
		
		resize_img.css("left","0");
		resize_img.css("top","0");
		var doc_width = $(window).width();
		var doc_height = $(window).height();
		/*if(doc_height < "600"){
			doc_height = "600";
		}
		if(doc_width < "1024"){
			doc_width = "1024";
		}*/
		var doc_ratio = doc_width/doc_height;
		
		var image_width = resize_img.width();
		var image_height = resize_img.height();
		var image_ratio = image_width/image_height;
		
		if(image_ratio<doc_ratio){
			var new_width = doc_width+10;
			var new_height = Math.round(new_width/image_ratio);
			var height_offset = Math.round((new_height-doc_height)/2);
			resize_img.css("top","-"+height_offset+"px");
		}
		else
		{
			new_height = doc_height+10;
			new_width = Math.round(new_height*image_ratio);
			var width_offset = Math.round((new_width-doc_width)/2);
			resize_img.css("left","-"+width_offset+"px");
		}
		
	resize_img.width(new_width);
	resize_img.height(new_height);
	}
	
	

	$(document).mousemove(function(e){
		if($(window).height() <= "600" || $(window).width() <= "1024"){
			smallscreen();
		}
		else
		{
			mousefollow(e);
		}
	});
	
	function smallscreen(){
			$('#layer_bg').css({left: '-0.5%',
							   	top: '-0.5%'});
			$('#layer_bg_glass').css({left: '-0.5%',
							   	top: '-0.5%'});
			$('#layer_bg_woman').css({left: '-0.5%',
							   	top: '-0.5%'});
			$('#layer_logo').css({left: '50%',
							   	top: '-9%'});
			$('#layer_video').css({left: '25%',
							   	top: '40%'});
			$('#layer_player').css({left: '75%',
							   	top: '36%'});
			
			if($(window).height() > $('#layer_bg img').height() || $(window).width() > $('#layer_bg img').width()){
				resize_bg("#content div.fullscreen img");
			}
			if($(window).height() > $('#layer_newsbg img').height() || $(window).width() > $('#layer_newsbg img').width()){
				resize_bg("#content_news div.fullscreen img");	
			}
			if($(window).height() > $('#content_band ul li img').height() || $(window).width() > $('#content_band ul li img').width()){
				resize_bg("#content_band ul li img");	
			}
	}
	
	function mousefollow(e)
			{
				versatz = -0.5;
				distanz = 0.2;
				div_id = 'layer_bg';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz+'%');
				
				versatz_x = -0.5;
				versatz_y = -4;
				distanz = 4;
				div_id = 'layer_bg_glass';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz_x+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz_y+'%');
				
				versatz_x = -0.5;
				versatz_y = -4;
				distanz = 2;
				div_id = 'layer_bg_woman';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz_x+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz_y+'%');
				
				versatz_x = 50;
				versatz_y = -3;
				distanz = 5;
				div_id = 'layer_logo';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz_x+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz_y+'%');
				
				versatz_x = 25;
				versatz_y = 45;
				distanz = 3;
				div_id = 'layer_video';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz_x+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz_y+'%');
				
				versatz_x = 75;
				versatz_y = 36;
				distanz = 3;
				div_id = 'layer_player';
				$('#'+div_id).css('left',((((e.pageX/$(document).width())-0.5)*2)*distanz)+versatz_x+'%');
				$('#'+div_id).css('top',((((e.pageY/$(document).height())-0.5)*2)*distanz)+versatz_y+'%');
			}
	
	
	
	$('#socialmedia a').live("mouseover", function(){
		span_id = $(this).find('span').attr('id');
		if(span_id == "facebook"){arrow_pos = '4px'};
		if(span_id == "twitter"){arrow_pos = '38px'};
		
		$("#socialmedia div#visit").stop().animate({
						opacity: "1",
						right: "-160px"
						},{
						queue: false,
						duration: 300,
						easing:'swing'
		});
	});
	$('#socialmedia a').live("mouseout", function(){
		$("#socialmedia div#visit").stop().delay(500).animate({
						opacity: "0",
						right: "-145px"
						},{
						queue: true,
						duration: 300,
						easing:'swing'
		});
	});
	
	$('.share img').live("click", function(){
		newWindow = window.open($(this).attr("alt"), "Facebook Share", "width=657,height=296");
		newWindow.focus();
	});
	
	
	
	$('a.imprint').live("click", function(){
		$.ajax({
			type: "POST",
			url: "ajax/imprint.php",
			success:	function(response){
							$("#text .text").html(response);
							$("#text").css("display", "block");
							$("#text").animate({
								opacity: "1"
								},{
								queue: false,
								duration: 800,
								easing:'swing'
							});
			}
		});
	});
	$('#text .close').live("click", function(){
		$("#text").animate({
			opacity: "0"
			},{
			queue: false,
			duration: 300,
			easing:'swing',
			complete: function() {
						$("#text").css("display", "none");
						}
		});
	});
	
	
	
	$('div.events span.text').live("mouseover", function(){
		$(this).find("div.share").stop().animate({
			height: "25px",
			overflow: "visible"
			},{
			queue: false,
			duration: 300,
			easing:'swing',
			complete: function(){$(this).find("div.share").css("overflow", "visible");}
		});
	});
	$('div.events span.text').live("mouseout", function(){
		$(this).find("div.share").stop().delay(300).animate({
			height: "0px"
			},{
			queue: true,
			duration: 300,
			easing:'swing',
			complete: function(){$(this).find("div.share").css("overflow", "hidden");}
		});
	});
	
	$('div#content_band div.left').css({opacity: "0.5"});
	$('div#content_band div.right').css({opacity: "0.5"});
	$('div#content_band div').live("mouseover", function(){
		$(this).stop().animate({
			opacity: "1"
			},{
			queue: false,
			duration: 300,
			easing:'swing'
		});
	});
	$('div#content_band div').live("mouseout", function(){
		$(this).stop().delay(300).animate({
			opacity: "0.5"
			},{
			queue: true,
			duration: 300,
			easing:'swing'
		});
	});
	$('div#content_band div').live("click", function(){
		var_left = parseInt($("#content_band ul").css("left"));
		if($(this).attr("class") == "left"){
			i = 1;
		}
		else
		{
			i = -1;
		}
		var_left = var_left+(i*100);
		var_pruef = $("#content_band ul").children().length*(-100);
		if(var_pruef >= var_left){
			var_left = 0;
		}
		if(var_left > "0"){
			var_left = var_pruef+100;
		}
		
		
		$("#content_band ul").animate({
			left: var_left+"%"
			},{
			queue: false,
			duration: 1000,
			easing:'swing'
		});
	});
	
	$(document).scroll(function(e){
		docheight = $(document).height();
		scrolltop = $(document).scrollTop();
		windowheight = $(window).height();
		new_docheight = docheight-windowheight;
		proz = (scrolltop/new_docheight)*100;
		$("#test").html(proz);
		
		var von = "-30";
		var bis = "70";
		var ab = "99"

		var_bottom = (von-bis)/(100-ab);
		proz = proz-ab;
		
		$("#content_contact div.scrollanim").stop().animate({
			bottom: von-(proz*var_bottom)+"px"
			},{
			queue: false,
			duration: 300,
			easing:'swing'
		});
	});
	
	
	$('div#content_contact .contact .message').css({opacity: "1"});
	$('div#content_contact form#formcontact input.button').live("click", function(){
		$.ajax({
			type: "POST",
			url: "ajax/contact.php",
			data: "inname="+$("#formcontact input.inname").attr("value")+"&inemail="+$("#formcontact input.inemail").attr("value")+"&inphone="+$("#formcontact input.inphone").attr("value")+"&inmessage="+$("#formcontact textarea.inmessage").val(),
			success:	function(response){
							$("div#content_contact .contact").html(response);
							$("div#content_contact .contact .message").delay(200).animate({
								bottom: "120px"
								},{
								queue: true,
								duration: 800,
								easing:'swing'
							}).delay(4000).animate({
								bottom: "-300px"
								},{
								queue: true,
								duration: 800,
								easing:'swing'
							});
			}
		});
	});
	
	
	
	new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1"
		}, [
		{
		title:"Prologue",
		mp3:"audio/01_Intro_bip.mp3"
		},
		{
		title:"Power Dive",
		mp3:"audio/02_Power_Dive_bip.mp3"
		},
		{
		title:"My Separation",
		mp3:"audio/03_My_Separation_bip.mp3"
		},
		{
		title:"Dreams Awake",
		mp3:"audio/04_Dreams_Awake_bip.mp3"
		},
		{
		title:"Kami",
		mp3:"audio/05_Kami_bip.mp3"
		},
		{
		title:"The Untouchable",
		mp3:"audio/06_Untouchable_bip.mp3"
		},
		{
		title:"Being Worth",
		mp3:"audio/07_Being_Worth_bip.mp3"
		},
		{
		title:"Dedication",
		mp3:"audio/08_Dedication_bip.mp3"
		},
		{
		title:"Your Hands",
		mp3:"audio/09_Your_Hands_bip.mp3"
		},
		{
		title:"Red Winter&prime;s Snow",
		mp3:"audio/10_Red_Winter_Snow_bip.mp3"
		},
		{
		title:"Outro",
		mp3:"audio/11_Outro_bip.mp3"
		},
		{
		title:"Smoke &amp; Mirrors",
		mp3:"audio/12_Smoke_And_Mirrors_bip.mp3"
		}], {
		swfPath: "js/jplayer",
		supplied: "mp3",
		wmode: "window"
	});
}); 
