//	JavaScript Document
/*
	@filename:	jquery-sabio.js
	@author:	j.wessel for con structores gmbh
	@date:		11|02|2008
*/

//	toggle the intro area on the homepage
var intro_cnt;
var rnd;
var myDelay;

var my_testimonial_delay;

var testimonial_cnt;

var thumbnail_cnt;
var my_thumbnail_delay;

function nullFunc() {
	// does nothing
}

var closelink = '<a href="javascript:nullFunc();" class="news_closelink">[-]</a>';

jQuery(
	function($) {
		intro_cnt = $('div#intro_main_con div.intro_main').size();
		$('div#intro_main_con div.intro_main').hide();
		
		//	rnd = Math.round((intro_cnt-1)*(Math.random()));
		
		deactivateInterval();
		$('div#intro_main_con div.intro_main:eq(1)').fadeIn(350).siblings('div.intro_main').css('display','none');
		
		
		activateInterval();
		
		$('div#intro_main_con div.intro_main .col_01 a').mouseover(
			function(e) {
				deactivateInterval();
				activateStage( $(this).parent().prevAll().size() );
			}
			
		);
			
		
		//	Count all news items
		news_cnt = $('div.news_item').size;
		$('div.news_item div.news_text').hide().append(closelink);	/*	initially hide long texts, needed for some engines like opera */

		//	Trigger 'show event': display of news long texts
		$('div.news_item p a.news_morelink').click(	/*	get links */
			function() {
				$('div.news_item p a.news_morelink').show();
				$('div.news_item div.news_text').hide();
				$(this).parent('p').next('div.news_text').slideDown(500);	/*	show this one long text, hide others */
				$(this).parent('div.news_text a.news_closelink').show();
				$(this).hide();

				/* return false; */

				//	Trigger 'hide event' display of news long texts
				$('a.news_closelink').bind("click", function(){
					$(this).parent('div.news_text').hide(); /*	hide long texts */
					$(this).parent('div.news_text a.news_closelink').hide();
					$('div.news_item p a.news_morelink').show();
					/* return false; */
					}
				);
				
				return false;
			}
		);
		
		
		//Function list box
		$('div#functions_list_trigger').mouseover(
			function(e) {
				$('div#functions_overlay_box').show();
			}
		);
		
		
		$('div#functions_list_trigger').mousemove(
			function(e) {			
				$('div#functions_overlay_box').css('left', $('div#functions_list_trigger').offset().left - $('div#functions_overlay_box').width() - 40);
				//	$('div#functions_overlay_box').css('top', $('div#functions_list_trigger').offset().top - $('div#functions_overlay_box').height() / 2 - 60);
				$('div#functions_overlay_box').css('top', e.pageY - $('div#functions_overlay_box').height() / 2);
				
				var aY = $('div#functions_overlay_box').css('top').split('px')[0];
				$('div#functions_overlay_box div#arrow').css('top', e.pageY - aY - $('div#functions_overlay_box div#arrow').height()/2);				
			}
		);
		
		
		$('div#functions_list_trigger').mouseout(
			function(e) {
				$('div#functions_overlay_box').hide();
			}
		);
		
		
		
		//Switching testimonials
		testimonial_cnt = $('div#client_votes div.client_vote').size();
		$('div#client_votes div.client_vote').hide();
		
		nextTestimonial();
		
		my_testimonial_delay = window.setInterval(nextTestimonial, 15000);
		currentTestimonial = 0;
		
		
		//Screenshot thumbnails
		thumbnail_cnt = $('p#screenshot_thumbnails a').size();
		
		$('p#screenshot_thumbnails a').hide();
		
		nextThumbnail();
		
		my_thumbnail_delay = window.setInterval(nextThumbnail, 4000);
	}
);

function switchStage(rnd) {

	rnd = Math.round((intro_cnt-1)*(Math.random()));
	
	$('div#intro_main_con div.intro_main:eq('+rnd+')').fadeIn(350).siblings('div.intro_main').css('display','none');
	//	console.log('switched');
}

function activateStage(num) {
	$('div#intro_main_con div.intro_main:eq('+num+')').show().siblings('div.intro_main').css('display','none');
	//	console.log('switched');
}


function nextTestimonial () {
	
	/*
	currentTestimonial = $('div#client_votes div.client_vote:visible').prevAll().size();
	
	++currentTestimonial;
	if(currentTestimonial >= $('div#client_votes div.client_vote').size() )
	{
		currentTestimonial = 0;
	}
	*/
	
	currentTestimonial = Math.round((testimonial_cnt-1)*(Math.random()));
	
	$('div#client_votes div.client_vote:eq('+currentTestimonial+')').css('display','block').siblings('div.client_vote').css('display','none');
}


function nextThumbnail () {
	
	currentThumbnail = $('p#screenshot_thumbnails a:visible').prevAll().size();
	
	++currentThumbnail;
	if(currentThumbnail >= thumbnail_cnt )
	{
		currentThumbnail = 0;
	}
	
	$('p#screenshot_thumbnails a:eq('+currentThumbnail+')').fadeIn(350).siblings('a').css('display','none');
}

function activateInterval () {
	myDelay = window.setInterval(switchStage,6000);
}

function deactivateInterval () {
	window.clearInterval(myDelay);
}



function openWindow(url) {

	popupWindow = window.open(
			url,
			'test',
			'height=600, width=800,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
			
	return false;
}
