/* #################################################

# Projekt	: Base JavaScripts

# Stand		: 03.08.10

# Autor		: Daniel Zander, Source-Media.com

#################################################### */





// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// FUNCS

// ----------------------------------------------------------------------



function rndm(){

	return String(Math.floor((Math.random()*1E16)));

}





// ---------- equal column ----------



function equalHeight(e){

	var max = 0;

	

	// get highest

	e.each(function(){

		var h = $(this).outerHeight(true);

		

		if ($('.head',this).length) // remove head

			h = h - ($('.head',this).outerHeight(true) * $('.head',this).length);

		

		if (h > max)

			max = h;

	});

	

	// set own height

	e.each(function(){

		

		$(this).height(

			$(this).height() + ( max - $(this).outerHeight(true) )

		);

	});

}







// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// READY

// ----------------------------------------------------------------------



$(function(){



// init > equal column



if ($('.equal').length)

	//setTimeout("equalHeight($('.equal'))",333);

	



// init > home slider



if ($('.slider').length){



	//$('.slider').slider();



	/*$("#teaser .content").easySlider({

		auto: true,

		continuous: true,

		numeric: true,

		speed: 600,

		pause: 8000

	});*/

}





// ---------- nav ----------



$('.nav ul.nav-sub').each(function(){ // init

	$(this).parent().addClass('show');

});

$('.nav li.show').live('mouseover',function(){

	$('ul.nav-sub',this).show();

}).live('mouseout',function(){

	$('ul.nav-sub',this).hide();

});



/* $('#nav li.show').hover(function(){

	$('ul.sub:not(.do)',this).slideDown(200,function(){

		$(this).addClass('do')}

	);

},function(){

	$('ul.sub',this).slideUp(200,function(){

		$(this).removeClass('do')}

	);

});*/





// ---------- pict ----------



$('a.thickbox').colorbox({

	transition:'elastic',

	opacity:0.85,

	slideshow:true,

	slideshowAuto:false,

	current: '{current} von {total}',

	maxWidth:'100%',

	maxHeight:'100%'

});



$('a.thickbox').each(function(){ $(this).append('<p />'); }); // zoom icon





// ---------- slider ----------



var currentPage = 1;



$('.slider .buttons span').live('click', function(){

	var par = $(this).parents('.slider:eq(0)');

	

	var timeout = setTimeout(function() {$("img").trigger("slidermove")}, 300);

	var fragments_count = $('.fragment',par).length;

	var fragmet_width = $('.fragment',par).width();

	var perPage = 1;

	var numPages = Math.ceil(fragments_count/perPage);

	var stepMove = fragmet_width*perPage;

	var container = $('.content',par);

	var firstPosition = 0;

	var lastPosition = -((numPages-1)*stepMove);

	

	if ($(this).hasClass('next')){

		currentPage ++;

		if (currentPage > numPages) {

			currentPage = 1;

			container.animate({'left': firstPosition});

			return;

		};

		container.animate({'left': -((currentPage - 1)*stepMove)});

	};

	if ($(this).hasClass('prev')) {

		currentPage --;

		if (currentPage < 1) {

			currentPage = numPages;

			container.animate({'left': lastPosition});

			return;

		};

		container.animate({'left': -((currentPage-1)*stepMove)});

	};

});





// ---------- form ----------



$('a.submit').click(function(){

	$('input[type=submit]','form[name='+$(this).attr('rel')+']').click();

	return false;

});



$('input[title]').each(function(){

	var t = $(this);



	if (!t.val())

		t.addClass('default').val(t.attr('title'));



	t.focus(function(){ //clear

		if (t.val() == t.attr('title')) // (!t.attr('maxlength') ? t.attr('title') : t.attr('title').substr(0,t.attr('maxlength'))))

			t.val('').removeClass('default');

		

	}).blur(function(){ //restore

		if (!t.val())

			t.addClass('default').val(t.attr('title'));

	});

});

});//ready
