///////////////////////////// sk/script /////////////////////////////////

var run_count=0;


jQuery(document).ready(function($){
	
	if(self.location.href.indexOf("http://www.superkleber.at")!=-1 || self.location.href.indexOf("http://superkleber.at")!=-1) {
		
	}
	else {
		return;
	};

	$('#start_bungee').live('mouseover', function(e){	
		$(this).attr('src', "/fileadmin/sk/bungee/start_bungee_act.png");	
	});
	
	$('#start_bungee').live('mouseout', function(e){	
		$(this).attr('src', "/fileadmin/sk/bungee/start_bungee.png");	
	});
	
	close_iframe = function(){
	location.hash = '';
	 $("#gewinnspiel").fadeOut("slow", function(){ $("#gewinnspiel").remove();$("body").closeDarker(); }); 

	}

	setHash = function(hash){
	
		if(hash.length==0 || hash=='/'){
		location.hash = '#gewinnspiel'; return;
		return;
		}
		
		
		hash = hash.replace("http://www.superkleber.at//", "");
		if(hash.indexOf("/")==0){
			my_hash = hash.substring(1, hash.length);
		} else {
			my_hash = hash;
		}
		location.hash = '#gewinnspiel-'+my_hash;
	}

	getHash = function(){
		return location.hash.replace(/gewinnspiel-?/, '');// = '#gewinnspiel-'+hash;
	}
	
	$('a[href*=#gewinnspiel]').live('click', function(e){
		e.preventDefault();
		
		location.hash = '#gewinnspiel';
		pageLoadHash(location.hash);
	
	});
	
	
	
	

	pageLoadHash = function(hash){
		//console.log('parent: '+hash);
		hash = hash.replace('#','');
		//if(run_count>0)	return;
		//run_count++;
	if(hash.indexOf("gewinnspiel")!=-1)  { 
		// Layer noch nicht da => anlegen und URL weitergeben
		if($("#gewinnspiel").length==0){
			
			$("body").darker();
			$("body").append('<div id="gewinnspiel"></div>');
			$("#gewinnspiel").css({
				position:"absolute",
				top:"0px",
				left:"0px",
				zIndex:"50000",
				display:"none"
			});

			$("#gewinnspiel").append('<a id="#close_iframe" href="javascript:close_iframe();"><img src="http://www.superkleber.at/fileadmin/sk/bungee/btnclose.png" style="position:absolute;top:50px;left:975px;"/><img src="http://www.superkleber.at/fileadmin/sk/bungee/load.gif" style="position:absolute;top:75px;left:979px;display:none;" id="_load"/></a><iframe width="971" height="700" allowTransparency="true" src="http://www.superkleber.at/gewinnspiel" scrolling="no" border="0" frameborder="0" id="gewinnspiel_iframe" name="gewinnspiel_iframe"></iframe>');
			$("#gewinnspiel").find("iframe").load(function(){
				$("#gewinnspiel").fadeIn("slow");
				//$('#close_iframe').live('click', function(e) { e.preventDefault();  $("#gewinnspiel").fadeOut("slow", function(){  $("#gewinnspiel").remove(); }); } );
				if(gewinnspiel_iframe){
					gewinnspiel_iframe.setHashEx(hash.replace(/gewinnspiel-?/, '/'));
				}
			});
		} 
		// Layer schon da => nur URL weitergeben
		else {
			//$('gewinnspiel_iframe').src = "http://www.superkleber.at/gewinnspiel/#"+hash.replace(/gewinnspiel-/);
			//location.hash = hash.replace(/gewinnspiel-/);
			//console.log(hash.replace(/gewinnspiel-/));
			if(gewinnspiel_iframe && gewinnspiel_iframe.setHashEx){
				gewinnspiel_iframe.setHashEx(hash.replace(/gewinnspiel-?/, '/'));
			}
		}

		
	}
	}
	//pageLoadHash(location.hash);
	jQuery.historyInit(pageLoadHash);
	
	$('#footer-logos img').mouseover(function(){
		var pfad=$(this).attr('src');
		var image=pfad.replace('/fileadmin/sk/images/logos/','');
		image=image.replace('.png','_act.png');
		$(this).addClass(pfad);
		$(this).attr('src','/fileadmin/sk/images/logos/'+image);
	});
	
	$('#footer-logos img').mouseout(function(){
		var image_inact=$(this).attr('class');
		$(this).attr('src',image_inact);
	});
	
	
//NO-FLASH VARIANTE
	if(!FlashDetect.installed){
		$('#skpolaroid-9').append('<div></div>');
		
		$('#flash-153').append('<a href="/produkte/produktberater/"><img src="/fileadmin/sk/images/produktberater.png" /></a>')
		$('#flash-153').css('top','355px');
		
		$('#skpolaroid-9').load("/?type=9876",function(){
			
			$('#pic_1').children().children().rotate(-20);
			$('#pic_2').children().children().rotate(10);
			$('#pic_3').children().children().rotate(-7);
			
			$('#pic_1 *').css('z-index','999').css("position", "relative");
			$('#pic_2 *').css('z-index','888').css("position", "relative");
			$('#pic_3 *').css('z-index','0').css("position", "relative");
			
		});

		$('#skpolaroid-9').css('top','185px');
		$('#skpolaroid-9').css('left','190px');
		
	}
});



