/* 
 * Dodanie do biblioteki pseudoklasy random, do pobierania losowych elementów
 */
jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});

/* 
 * Ukrywa/pokazuje poszczeg�lne informacje w boxie "solutions".
 */
function changeSolution(handle){
//	$('.solutions_list').hide();
	
	if($(handle).attr('rel')=='up'){
		$parent = $(handle).parent(); 
		if($parent.next('div').is(':hidden')) {
			$('.arrow').attr('src','fileadmin/templates/images/down.gif');
			$(handle).attr('src','fileadmin/templates/images/down.gif');
			$(handle).attr('rel','down');
		}
	}else{
		$('.arrow').attr('src','fileadmin/templates/images/down.gif');
		$('.arrow').attr('rel','down');
		$(handle).attr('src','fileadmin/templates/images/up.gif');
		$(handle).attr('rel','up');
//		$(handle2).show();
	}	
}
/*
 * Zmienia przyklad w boxie "web_app" lub "web_site" w zaleznosci od typu(mode).
 * handle - uchwyt na przycisk z numerem przykladu.
 */
function changeWeb(mode,handle){
	$(handle).parent().find('.active').removeClass('active');
	$(handle).addClass('active');
//	$(handle).parent().parent().find('.title_text div.active').attr('class','hidden');
	
	$('#web_'+mode+' .middle_box_cont div.active').fadeOut(1000);
	$('#'+mode+ $(handle).attr('rel') ).fadeIn(1000);
	$('#web_'+mode+' .middle_box_cont div.active').attr('class','hidden');
	$('#'+mode+ $(handle).attr('rel') ).attr('class','active');
	
	$('#'+mode+ $(handle).attr('rel') + '_title').attr('class','active');
}

/*
 * Przewija przyklad w boxie(web_app lub web_site). 
 */
function switchWeb(mode){
	var number=$('#web_'+mode+' .title_pagination a.active').attr('rel');
	if(number==4){
		var handle=$('#web_'+mode+' .title_pagination a:first-child');
	}else{
		var handle=$('#web_'+mode+' .title_pagination a.active').next();
	}
	changeWeb(mode,handle);
}

/*
 * G��wny skrypt
 */
$(document).ready(function(){
	// Start przewijania przyklad�w w boxach.
	
	
	var switch_site = window.setInterval("switchWeb('site')", 5000); 
	var switch_app=window.setInterval("switchWeb('app')", 5000);
	
	// Zmiana strzałki w boxie "solutions".
	$('.sol').click(function(){
		changeSolution($(this).find('.arrow'));
		return false;
	});
	
	// Zmiana informacji w boxie "solutions".
	$(function() {
		$("#solutions_cont" ).accordion({
			collapsible: false,
			header: 'div.sol',
			autoHeight: false
		});
	});
	
	//Pokazanie pierwszego elementu listy w boxie "latest"
	$('.latest li:first div').show();		
	// Zmiana informacji w boxie "latest"
	$('.latest a').click(function(){
		if($(this).attr('href')!='#') 
			return true; 
		$('.latest_list').hide();
		$(this).parent().find('.latest_list').show();
		return false;
	});
	// Zmiana przyk�adu w boxie "web_app" i wy��czenie przewijania tego boxu
	$('#web_app .title_pagination a').click(function(){
		if($(this).hasClass('active')){}else{
			changeWeb('app',$(this));
			window.clearInterval(switch_app);
		}
		return false;
	});
	// Zmiana przyk�adu w boxie "web_site" i wy��czenie przewijania tego boxu.
	$('#web_site .title_pagination a').click(function(){
		if($(this).hasClass('active')){}else{
			changeWeb('site',$(this));
			window.clearTimeout(switch_site);
			window.clearInterval(switch_site);
		}
		return false;
	});
	
	// FLIP Przewijanie klientow na froncie
	/*$(function() { 
		setInterval(function() {
			var $to_show = $('#clients_cont a.client_hide:random');
			var $to_hide = $('#clients_cont a.active');
			var src = $to_hide.children().attr('src');
			var alt = $to_hide.children().attr('alt');
			var title = $to_hide.children().attr('title');
			$('#clients_cont a.active').flip({
				direction:'lr',
				speed: 300,
				content: $to_show.html(),
				onEnd: function(){
					$to_hide.removeClass('active');
					$to_show.children().attr('src',src);
					$to_show.children().attr('alt',alt);
					$to_show.children().attr('title',title);
					if($to_hide.next().is(':hidden')) 
						$('#clients_cont a:first').addClass('active');
					else
						$to_hide.next().addClass('active');
				}

			});
		},3000);
	});*/
	
	//Przenikanie logow klientow, przenisione do wtyczki
	/*
	$(function() { 
		setInterval(function() {
			var n = $("#clients_cont div").size();
			if(n < 2) return;
			
			var $to_hide = $('#clients_cont div:visible');
			if($to_hide.attr('id') == $("#clients_cont div:last").attr('id'))
				var $to_show = $("#clients_cont div:first");				
			else 
				var $to_show = $to_hide.next();	
			$to_hide.fadeOut(1000);
			$to_show.fadeIn(1000);			
		},5000);
	});
	
	//Przenikanie logow partnerow
	$(function() { 
		setInterval(function() {
			var n = $("#partners_cont div").size();
			if(n < 2) return;			 
			var $to_hide = $('#partners_cont div:visible');
			if($to_hide.attr('id') == $("#partners_cont div:last").attr('id'))
				var $to_show = $("#partners_cont div:first");				
			else 
				var $to_show = $to_hide.next();	
			$to_hide.fadeOut(1000);
			$to_show.fadeIn(1000);			
		},5000);
	});
	*/
	
	
	/* nie najladniej ale robione w piate wieczorem o 18:23*/
	if($('#hover_prev_site span').html() == ''){
		$('.hover_prev_site').hide();
		$('.prev_site').hide();
	}
	if($('#hover_next_site span').html() == ''){
		$('.hover_next_site').hide();
		$('.next_site').hide();
	}
	
	$('#hover_next_site,#hover_prev_site').hover(
	  function () {
		    $(this).stop(true, true).animate({opacity: 1});
		  }, 
	  function () {
		  $(this).stop(true, true).animate({opacity: 0});
	  });
	
	$('#hover_next_site,#hover_prev_site').click(function(){
		if($('a',this).attr("href"))
			document.location.href = $('a',this).attr("href");
	});
})