/*-----------------------------------------
 
 copyright 2010 by opendo
 
 
 Author: Georg Paul
 
 Author URI: http://www.opendo.at
 
 -------------------------------------------*/


$(document).ready(function(){

	// TEMP !!!!!!!!!!!
	if ($('body').hasClass('page-3937')) {
		
		$('body').addClass('organigramm');
		$('.csc-sitemap ul:first').attr('id', 'organigramm');
		
		$('#organigramm > li').each(function(i){
			var x = i + 1;
			$(this).addClass('nth-child-' + x);
		})				
	}	
	
	// main nav
	$('#main-nav li a').bind('focus', function(){
		$(this).nextAll('ul').css('display', 'block');
	})
	
	$('#main-nav li li:last-child a:last-child').bind('blur', function(){
		$(this).parent().parent().css('display', 'none');
		//console.log($(this).parent().parent());
	})	
	
	$('#main-nav li ul').hover(
		function(){
			$(this).prev('a').addClass('active-tab');
		},
		function(){
			$(this).prev('a').removeClass('active-tab');
		}
	)
	
	// form defaults
	$('#search-field').formDefaults();


	// init Innerfade-Plugin
		if ($('#slideshow-teaser ol li').length > 1) {
			
			$('#slideshow-teaser ol').innerfade(
			{
				animationtype: 'fade',
				speed: 1000,
				timeout: 10000,
				type: 'sequence'
			});
			
		}
	appendProgressBar();

	
	// content nav
	if (!$('body').hasClass('home')) $('#content-nav').show();
	
	// temp
	$('#print-page').hide();
	
	
	$('#print-page a').bind('click', function(event){
		event.preventDefault();
		
		window.print();
	})
	$('#top-link a').bind('click', function(event){
		event.preventDefault();
		
		window.location.hash = '#top';
	})
	
	
	 
	if ($.browser.msie) {
		// give class to IE for second last teaser
		if ($('#cms-content .teaser:last-child').length > 0)
			$('#cms-content .teaser:last-child').prev().addClass('second-last-teaser');
		
		// flash player -> set wmode
		//$('.tx-flvplayer2-pi1 object').append('<param name="wmode" value="transparent" />');
	}
	
});


function appendProgressBar(){
	if ($('body').hasClass('home')) {
		$('#slideshow-teaser').append('<div id="progress-bar"><span></span></div>');
		var progressPixelWidth = 16;
		var teaserCount = $('#slideshow-teaser ol li').length;

	
		var progressBarWidth = (progressPixelWidth * teaserCount) + 'px';
		$('#progress-bar').css('width', progressBarWidth);
	}
}

function refreshProgressBar(activeTeaser){
	
	var teaserCount = $('#slideshow-teaser ol li').length;
	
	var teaserPosition = $(activeTeaser).prevAll('li').length;
	if (teaserPosition == 0) teaserPosition =  teaserCount;
	
	var bgPositionOffset = -16 * teaserPosition;
	$('#progress-bar span').css('background-position', '0 ' + bgPositionOffset + 'px')
	
	
}

function fadeOutCallback(){
	//$('.header_teaser_content p').hide();
	
}


function getURLParam(name) {
	
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	
	if( results == null )
		return "";
	else
		return results[1];
		
}

