
/************************/
/*** MAIN *************/
/************************/

$(document).ready(function(){
	//swapAndPreload();
	
	// banner INIT
	if(typeof(bannerImagePaths)!='undefined'){
		bannerInit("banner");
		bannerAnimate("banner");
	}
	
	// teaser home page 
	if(typeof(teaserImagePaths)!='undefined'){
		teaserInit();
		teaserAnimate();
	}
	
	
	// highlight important words
	if(typeof(highStrings)!='undefined'){	
		$.each(highStrings, function(index, string) { 
			$('#content:contains("'+string+'")').html(function(i,e){
				var p = new RegExp(string,"g");
				return e.replace(p,$('<span />').addClass('blue').text(string).wrap('<div />').parent().html());			 
			});
		});
	}
	
	
	/*$(#content).filter(function() {
		return /\d{3}-\d{3}-\d{4}/.test( $(this).text() );
	});*/
	
	// specifics for left sub menu 
	$(".section ul li").hover(
		function () {
			if(!$(this).hasClass("selected"))$(this).addClass("over");
		}, 
		function () {
			$(this).removeClass("over");
		}
	);
	$(".section ul li").click(function() {
		window.location=$(this).children("a").attr("href");
	});
	
	// set all external link to open new window
	$('a[href^="http://"]').attr("target","_blank");
	
});

/***********************
banner ANIMATION
***********************/
var bannerIndex = 0;
var duration = 1000;
var offset = 200;

function bannerInit(element){

	$("#bannerBg").css("opacity","0").css("background","transparent url("+bannerImagePaths["bg"]+") no-repeat");
	$("#bannerText1").css("left",bannerImagePaths["textLeft"]+"px").css("opacity","0").css("top","42px");
	$("#bannerText2").css("left",bannerImagePaths["textLeft"]+"px").css("opacity","0").css("top","67px");
	if(bannerImagePaths["logo"]!=undefined){
		$("#bannerLogo").css("background","transparent url("+bannerImagePaths["logo"]+") no-repeat");
		$("#bannerLogo").css("width",bannerImagePaths["logoWidth"]);
		$("#bannerLogo").css("height",bannerImagePaths["logoHeight"]);
		$("#bannerLogo").css("left",bannerImagePaths["logoLeft"]+"px");
		$("#bannerLogo").css("top",bannerImagePaths["logoTop"]+"px");
		$("#bannerLogo").css("opacity","0");
	}
	
}

function bannerAnimate(element){
	
	//$("#bannerBg").animate({opacity:1,left:0},duration*2);
	$("#bannerBg").animate({opacity:1},duration*2);
	$("#bannerTextBg").delay(duration).animate({left:0},duration);
	if(bannerImagePaths["logo"]!=undefined)
		$("#bannerLogo").delay(duration*2+offset).show().animate({opacity:1},duration);
	$("#bannerText1").delay(duration*2+offset).show().animate({opacity:1},duration);
	$("#bannerText2").delay(duration*2+offset+offset).show().animate({opacity:1},duration);
	
}

function teaserInit(){
	//$("#hp-teaser-galaxie").css("background","transparent url("+teaserImagePaths["galaxie"]+") no-repeat").css("left","30px");
	//$("#hp-teaser-tkc").css("background","transparent url("+teaserImagePaths["tkc"]+") no-repeat").css("left","275px");
	//$("#hp-teaser-s360").css("background","transparent url("+teaserImagePaths["s360"]+") no-repeat").css("left","500px");
	//$("#hp-teaser-ctv").css("left","715px").css("opacity","0").css("background","transparent url("+teaserImagePaths["ctv"]+") no-repeat");
	//$("#hp-teaser-sm").css("left","715px").css("opacity","0").css("background","transparent url("+teaserImagePaths["sm"]+") no-repeat");
	//$("#hp-teaser-mc").css("left","715px").css("opacity","0").css("background","transparent url("+teaserImagePaths["mc"]+") no-repeat");
	$("#hp-teaser-galaxie").css("left","715px").css("background","transparent url("+teaserImagePaths["galaxie"]+") no-repeat")//.css("left","30px");
	$("#hp-teaser-tkc").css("left","715px").css("background","transparent url("+teaserImagePaths["tkc"]+") no-repeat")//.css("left","275px");
	$("#hp-teaser-s360").css("left","715px").css("background","transparent url("+teaserImagePaths["s360"]+") no-repeat")//.css("left","500px");
	$("#hp-teaser-ctv").css("left","715px").css("background","transparent url("+teaserImagePaths["ctv"]+") no-repeat");
	$("#hp-teaser-sm").css("left","715px").css("background","transparent url("+teaserImagePaths["sm"]+") no-repeat");
	$("#hp-teaser-mc").css("left","715px").css("background","transparent url("+teaserImagePaths["mc"]+") no-repeat");
}

function teaserInitElement(element){
	element.css("left","715px");
	element.attr("ready","true");
}

function teaserAnimate(){
	/*
	$("#hp-teaser-galaxie").delay(duration*3).animate({opacity:0,left:"-816px"},duration).delay(duration*4).animate({left:"715px"},1).animate({opacity:1,left:"30px"},duration);
	$("#hp-teaser-tkc").delay(duration*3).animate({opacity:0,left:"-404px"},duration).delay(duration*4).animate({left:"715px"},1).animate({opacity:1,left:"275px"},duration);
	$("#hp-teaser-s360").delay(duration*3).animate({opacity:0,left:"-208px"},duration).delay(duration*4).animate({left:"715px"},1).animate({opacity:1,left:"500px"},duration);
	$("#hp-teaser-ctv").delay(duration*3).animate({left:"715px"},1).animate({opacity:1,left:"30px"},duration).delay(duration*4).animate({opacity:0,left:"-816px"},duration);
	$("#hp-teaser-sm").delay(duration*3).animate({left:"715px"},1).animate({opacity:1,left:"255px"},duration).delay(duration*4).animate({opacity:0,left:"-404px"},duration);
	$("#hp-teaser-mc").delay(duration*3).animate({left:"715px"},1).animate({opacity:1,left:"500px"},duration).delay(duration*4).animate({opacity:0,left:"-208px"},duration,function() {
		teaserInit();
		teaserAnimate();
	});
	*/
	$("#hp-teaser-galaxie").attr("ready","false").animate({left:"30px"},duration).delay(duration*3).animate({left:"-816px"},duration,function(){teaserInitElement($(this));});
	$("#hp-teaser-tkc").attr("ready","false").animate({left:"275px"},duration).delay(duration*3).animate({left:"-404px"},duration,function(){teaserInitElement($(this));});
	$("#hp-teaser-s360").attr("ready","false").animate({left:"500px"},duration).delay(duration*3).animate({left:"-208px"},duration,function(){teaserInitElement($(this));});
	$("#hp-teaser-ctv").attr("ready","false").delay(duration*4).animate({left:"30px"},duration).delay(duration*3).animate({left:"-816px"},duration,function(){teaserInitElement($(this));});
	$("#hp-teaser-sm").attr("ready","false").delay(duration*4).animate({left:"255px"},duration).delay(duration*3).animate({left:"-404px"},duration,function(){teaserInitElement($(this));});
	$("#hp-teaser-mc").attr("ready","false").delay(duration*4).animate({left:"500px"},duration).delay(duration*3).animate({left:"-208px"},duration,function() {
		teaserInitElement($(this));
		startTeaserAnimate();
	});
	
}

function startTeaserAnimate(){
	var ready = true;
	$(".hp-teaser").each(function(){
		if($(this).attr("ready")!="true"){
			ready = false;
		}
	})
	
	if(ready){
		teaserAnimate();
	}else{
		setTimeout('startTeaserAnimate()',100);
	}
}
