// set special classes in inputFields
function inputFieldClasses() {
	jQuery('.searchWord').live('focus', function(){
		jQuery(this).focus(function(){
			jQuery(this).val('');
		});
	});
}

// animation
function amimateIntro() {
	if (jQuery('#bodyOverlay').length == 0){
		jQuery('body').prepend('<div id="bodyOverlay">');
	}
	jQuery('#brandBox').append('<div id="brandBoxOverlay">');
	jQuery('#content').append('<div id="contentOverlay">');
	jQuery('#marginalBox').append('<div id="marginalBoxOverlay">');
	jQuery('#layoutBox').append('<div id="layoutBoxOverlay">');
	var layoutBoxOverlayHeight = parseInt(jQuery('#marginalBox').height())-101;
	jQuery('#layoutBoxOverlay').height(layoutBoxOverlayHeight);
	var marginalBoxOverlayHeight = parseInt(jQuery('#marginalBoxOverlay').height())-4;
	jQuery('#marginalBoxOverlay').height(marginalBoxOverlayHeight);
	// hide
	jQuery('#brandBox,#content,#marginalBox,#layoutBox').css({'opacity':0});
	// Animations
	jQuery('#bodyOverlay').animate({opacity: 0},2600,function(){jQuery(this).hide().remove();});
	jQuery('#brandBox').css({'top':'20px'}).delay(1000).fadeIn().animate({opacity: 1,top:'117px','filter':''});
	jQuery('#content').css({'margin-top':'110px'}).delay(1000).animate({opacity: 1,'margin-top':'82px','filter':''},500);
	jQuery('#marginalBox').css({'margin-top':'110px'}).delay(1000).animate({opacity: 1,'margin-top':'-82px','filter':''},500);
	jQuery('#layoutBox').css({'top':'10px'}).delay(1000).animate({opacity: 1,top:'35px','filter':''},500);
	jQuery('#brandBoxOverlay').delay(2000).animate({opacity: 0},1000,function(){jQuery(this).hide().remove();});
	jQuery('#contentOverlay').delay(2100).animate({opacity: 0},1000,function(){jQuery(this).hide().remove();});
	jQuery('#marginalBoxOverlay').delay(2200).animate({opacity: 0},1000,function(){jQuery(this).hide().remove();});
	jQuery('#layoutBoxOverlay').delay(2300).animate({opacity: 0},1000,function(){jQuery(this).hide().remove();});
}

function removeLayoutBox() {
	if(jQuery('#layoutBoxOverlay').length == 0){
		jQuery('#layoutBox').append('<div id="layoutBoxOverlay">');
	}
	var layoutBoxOverlayHeight = parseInt(jQuery('#marginalBox').height())-105;
	jQuery('#layoutBoxOverlay').height(layoutBoxOverlayHeight).width(79);
	jQuery('#layoutBoxOverlay').animate({opacity: 1},100);
	jQuery('#layoutBox').animate({opacity: 0,'filter':''},100);
	jQuery('#layoutBoxOverlay').animate({opacity: 0},300,function(){
		jQuery(this).hide().remove();
		jQuery('#layoutBox').css({'display':'none'});
	});
}
function showLayoutBox() {
	if(jQuery('#layoutBoxOverlay').length == 0){
		jQuery('#layoutBox').append('<div id="layoutBoxOverlay">');
	}
	var layoutBoxOverlayHeight = parseInt(jQuery('#marginalBox').height())-105;
	jQuery('#layoutBoxOverlay').height(layoutBoxOverlayHeight).width(79);
	jQuery('#layoutBox').css({'opacity':0,'display':'block'});
	jQuery('#layoutBoxOverlay').animate({opacity: 1},100);
	jQuery('#layoutBox').animate({opacity: 1,'filter':''},100);
	jQuery('#layoutBoxOverlay').animate({opacity: 0},300,function(){
		jQuery(this).hide().remove();
	});
}

// setFixedElements
function setFixedElements() {
	// set the vars for fixed Objects
	var bodyWidth = jQuery('body').width();
	var microSiteWidth = jQuery('#microSite').width();
	if(bodyWidth == microSiteWidth){var bodyWidth = 1000;}
	var marginSite = (parseInt(bodyWidth)-parseInt(microSiteWidth))/2;
	var layoutBoxHeight = parseInt(jQuery('#marginalBox').height())-97;
	var layoutBoxWidth = parseInt(jQuery('#marginalBox').width());
	jQuery('#brandBox').css({'left':marginSite});
	jQuery('#layoutBox').css({'height':layoutBoxHeight});
	if(jQuery('#layoutStyle').length == 0){
		jQuery('head').append('<style id="layoutStyle">#brandBox {left:'+marginSite+'px;}#layoutBox{height:'+layoutBoxHeight+'px;}</style>');
	} else {
		jQuery('#layoutStyle').remove();
		jQuery('head').append('<style id="layoutStyle">#brandBox {left:'+marginSite+'px;}#layoutBox{height:'+layoutBoxHeight+'px;}</style>');
	}
	if(bodyWidth < 1160 && jQuery('#layoutBox').css('display') == 'block') {
		removeLayoutBox();
	}
	if(bodyWidth > 1160 && jQuery('#layoutBox').css('display') == 'none') {
		showLayoutBox();
	}
}

// ramdomBackground
function randomBackground() {
	var start = new Date().getTime();
	var setNewBackground = false;

		// no last visit set?
	if (!jQuery.cookie('lastVisit')) {
		setNewBackground = true;
	} else if ((start - parseInt(jQuery.cookie('lastVisit'))) > 600000) {
		// 10 minutes * 60 seconds * 1000 milliseconds
		setNewBackground = true;
	}

	if (!jQuery.cookie('randomBg') || setNewBackground == true) {
		var rndNum = Math.floor(Math.random() * 4);
		jQuery.cookie('randomBg',rndNum);
	} else {
		var rndNum = jQuery.cookie('randomBg');
	}

	jQuery.cookie('lastVisit', start);
	jQuery('html, #bodyOverlayBox').css('background-image','url(img/body4.gif)','background-repeat','repeat-y');
}

// on window resize
jQuery(window).bind('resize', function() {
	if($.browser.msie && $.browser.version == '6.0'){
	} else {
		setFixedElements();
	}
});

// set flashVideo
function setFlashVideo() {
	if(jQuery('div#videoContainer').length != 0){
		var params = {
			allowfullscreen: "true",
			allowscriptaccess: "always",
			wmode: "opaque"
		};
		swfobject.embedSWF("our-new-look/stoxx_design_556x312.swf", "videoContainer", "558", "312", "10.0.0", "", '', params);
	}
}

jQuery(document).ready(function(){
	inputFieldClasses();
	if($.browser.msie && $.browser.version == '6.0'){
	} else {
		$html = jQuery('html').addClass('hasJs');
		randomBackground();
		if (jQuery.cookie('animation') != 'done') {
			amimateIntro();
			jQuery.cookie('animation','done');
		}
		setFixedElements();
//		jQuery.history.init(function(hash){
//			if(hash) {
//				jQuery('#microSite').load(hash+' #microSite > *', function() {
//					setFlashVideo();
//					jQuery(window).scrollTop(0);
//				});
//			}
//		});
//		jQuery('#mainNav a, #subNav a, .moreLink, .learnMore, .imprintLink, #branding, .internalLink').live('click', function(e){
//			var url = jQuery(this).attr('href');
			// manipulate absolute url to relative
//			if(url.match('^http')){
//				url = url.split('/').pop();
//			}
//			jQuery.history.load(url);
//			return false;
//		});
    
		setFlashVideo();
	}

});
