// 10-splashpage.js
// hovers
function initHovers () {
	
	// set grey transparent overlays
	jQuery('.teaser').not('.template-location').prepend(jQuery(document.createElement('div')).addClass('helper-transparent'));
	jQuery('.teaser .helper-transparent').each(function(){
		jQuery(this)
			.width(jQuery(this).parent().width())
			.height(jQuery(this).parent().height());
	});
		
	// http://plugins.jquery.com/project/hoverIntent
	var durationFadeIn = 100; // ms
	var durationFadeOut = 200; // ms
	var hiConfig = {
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 100, // number = milliseconds for onMouseOver polling interval
		timeout: 50, // number = milliseconds delay before onMouseOut
		over: function() {
			
			cc = jQuery(this).children('.container-content');			
			if (cc) {
				position = cc.parent().position();				
				if (position.left > (jQuery(window).width() - 500)) {
					cc.parent().addClass('teaser-slideout-left');
					if (!(jQuery(cc).children('.temp-image-holder').length > 0)) {
						cc.append(jQuery(document.createElement('div')).addClass('temp-image-holder').prepend(jQuery(cc.prev('.container-image').children(":first").clone().wrap('<div class="temp-image-holder">'))))
					}
				} else {
					cc.parent().removeClass('teaser-slideout-left');
					if (!(jQuery(cc).children('.temp-image-holder').length > 0)) {
						cc.prepend(jQuery(document.createElement('div')).addClass('temp-image-holder').prepend(jQuery(cc.prev('.container-image').children(":first").clone().wrap('<div class="temp-image-holder">'))))
					}
				}
				cc.fadeIn(durationFadeIn);
				
				// css-fix: set p to 3 lines if h2 has 2 lines 
				if (jQuery('h2', cc).height() > 40) {
					jQuery('p', cc).height('48px');
				}
			}
        },
        out: function() {
			jQuery(this).children('.container-content').fadeOut(durationFadeOut);
        }
	};
	jQuery('li.teaser').hoverIntent(hiConfig);
		
}




// content filler
function fillContents () {	
	// add rows
	while (jQuery('#container-main').height() < jQuery(window).height()) {
		jQuery('#container-main').height(jQuery('#container-main').height() + constColumnHeight);
		jQuery('#container-main').append(jQuery('#row1').clone(true));
	}
	
	// add columns
	while (jQuery('#container-main').width() < jQuery(window).width()) {
		jQuery('#container-main').width(jQuery('#container-main').width() + constColumnWidth);
		if (columns[columnsHIndex]) {
			jQuery('.row').each(function(){
				jQuery(this).append(columns[columnsHIndex].clone(true));
			});
			columnsHIndex++;
			if (columnsHIndex > 4) {
				columnsHIndex = 0;
			}
		}
	}
}




// @todo remove splashpage redirect for IE6/7
function checkBrowserName(name){  
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf(name.toLowerCase())>-1) {  
		return true;  
	}  
	return false;  
}
if (checkBrowserName('MSIE 7') || checkBrowserName('MSIE 6')) {
	if (window.location.href.match(/bar/)) {
		window.location = "http://bar-jeder-vernunft.de/de/home/";
	} else {
		window.location = "http://tipi-am-kanzleramt.de/de/home/";
	}
}



// init-splashpage.js
// init global vars
var columns = [];
var columnsHIndex = 0;
//@todo get from element
var constColumnWidth = 205; 
//@todo get from element
var constColumnHeight = 593; 

// init js
jQuery(document).ready(function() {

	// init hovers
	initHovers();

	// get columns for copying
	jQuery("#row1 > ul").each(function(){
		columns.push(jQuery(this));
	});
	
	// set #container-main as reference frame
	jQuery('#container-main').width(constColumnWidth * 5);
	jQuery('#container-main').height(constColumnHeight);

	// init
	fillContents();
	jQuery(window).resize(function() {
		fillContents();
	});

});

