﻿
/************************/
/*** MAIN *************/
/************************/

$(document).ready(function(){
	swapAndPreload();
	menuInit();
	
	// TEASER INIT
	if(typeof teaserImagePaths != 'undefined'){
		teaserInit("teaser");
		animate("teaser");
	}
});

function menuInit(){
	$("#menu .element").hover(function(){
		$(this).addClass("over");
	},function(){
		$(this).removeClass("over");
	});
}

function swapAndPreload(){

		//set the hover behaviour
	$(".swap").each(function(){
		// preload images
		var img = new Image();
		img.src=this.src.replace(/([-_])out/,'$1over');
		//set the hover behaviour
		$(this).hover(function(){
			this.src=this.src.replace(/([-_])out/,'$1over');
			//$(this).animate({opacity:0},1000);
		},function(){
			this.src=this.src.replace(/([-_])over/,'$1out');
			//$(this).animate({opacity:1},1000);
		});
		//set the cursor style
		this.style.cursor="pointer";
	});
}
	/*
	$("img").each(function(tag){
		if(/\$swap/.test(tag.className)){
			tag.onmouseover = function(){
				this.src=this.src.replace(/([-_])out/,'$1over');
			}
			tag.onmouseout = function(){
				this.src=this.src.replace(/([-_])over/,'$1out');
			}
			tag.style.cursor="pointer";
		};
		if(/\$preload/.test(tag.className)){
			var img = new Image();
			img.src=tag.src.replace(/([-_])out/,'$1over');
		};
	});*/



/***********************
TEASER ANIMATION
***********************/
var teaserIndex = 0;
var duration = 1000;
var offset = 300;

function teaserInit(element){
	$("#"+element+"1").css("background","transparent url("+teaserImagePaths[0]+") no-repeat");
	$("#"+element+"2").css("display","none");
	$("#"+element+"2").css("background","transparent url("+teaserImagePaths[0]+") no-repeat");
	// TeaserTV
	$("#"+element+"TV1").css("background","transparent url("+teaserTVImagePaths[0]+") no-repeat");
	$("#"+element+"TV2").css("display","none");
	$("#"+element+"TV2").css("background","transparent url("+teaserTVImagePaths[0]+") no-repeat");
}

function animate(element){
	
	$("#"+element+"1").css("background","transparent "+$("#"+element+"2").css("background-image")+" no-repeat");
	$("#"+element+"TV1").css("background","transparent "+$("#"+element+"TV2").css("background-image")+" no-repeat");
	$("#"+element+"2").hide().css("opacity","0").css("background","transparent url("+teaserImagePaths[teaserIndex]+") no-repeat");
	$("#"+element+"TV2").hide().css("opacity","0").css("background","transparent url("+teaserTVImagePaths[teaserIndex]+") no-repeat");
	$("#"+element+"2").show().animate({opacity:1},duration);
	$("#"+element+"TV2").show().delay(offset).animate({opacity:1},duration);
	if(teaserIndex==teaserImagePaths.length-1)
		teaserIndex = 0;
	else
		teaserIndex++;
	setTimeout('animate("'+element+'")', duration*6);
	
}

