
$(document).ready(function(){
	
	fancyStart();
	
	$('.hp_box .opacity').css({opacity:0.5});
	$('.hp_popul_item .opacity').css({opacity:0.5});
	$('.hp_newsletter .opacity').css({opacity:0.5});
	
	$('.clear_on_blur').each(function(){
		val = this.value;
		eval("this.onfocus = function() { if (this.value=='"+val+"') { this.value = ''; } }");
		eval("this.onblur = function() { if (this.value=='') { this.value = '"+val+"'; } }");
	});
});

function fancyStart()
{
	$(".fancy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'overlayOpacity':	0.9,
		'overlayColor'	:	'#000000',
		'speedIn'		:	600,
		'speedOut'		:	200
	});
}

function logo_slideshow_next(k)
{
	if ($('#logo_slideshow'))
	{
		kp = (k+1);
		if (kp>13) kp = 1;
		kp2 = (kp+1);
		if (kp2>13) kp2 = 1;
		if (kp2>14) kp2 = 2;
		//window.console.log(k+'/'+kp+'/'+kp2);
		
		$('#slide_'+k).animate({opacity: 0}, 1000);
		$('#slide_'+kp).animate({opacity: 1}, 1000);
		$('#slide_'+kp2).show();
		$('#slide_'+kp2).css({opacity:0});
		if (isset('lss')) { clearTimeout(lss); }
		lss = setTimeout("logo_slideshow_next("+kp+");", 2000);
	}
}

function logo_slideshow()
{
	div = $('#logo_slideshow');
	text = '';
	for (k = 1; k < 14; k++)
	{
		if (k < 10) ko = '0'+k; else ko = k;
		text += '<div id="slide_'+k+'" class="logo_slide" style="display: none;"><img src="'+DOC_ROOT+'res/img/logos/logo_small_'+ko+'.png" alt="Zaufali nam" /></div>';
	}
	div.html(text);
	for (k = 1; k < 14; k++)
	{
		$('#slide_'+k).show();
		$('#slide_'+k).css({opacity:0});
	}
	logo_slideshow_next(1);
}

function hp_start()
{
	
}

function portfolio_start()
{
	portfolio_arrows();
}

function portfolio_arrows()
{
	left = parseInt($('#scrollers').css('left'));
	max = parseInt($('#scrollers').attr('max'));
	//window.console.log(left);
	if (left == 0)
	{
		$('#arrow_left').animate({opacity: 0},200,function(){$(this).hide();});
	}
	if (left < 0)
	{
		$('#arrow_left').show().animate({opacity: 1},200);
	}
	if (left <= max)
	{
		$('#arrow_right').animate({opacity: 0},200,function(){$(this).hide();});
	}
	if (left > max)
	{
		$('#arrow_right').show().animate({opacity: 1},200);
	}
}

function portfolio_cats(cat)
{
	$('#portfolio .menu .txt.active').animate({height: 0},500).removeClass('active');
	$('#mt'+cat).animate({height: 120},500).addClass('active');
	$.get(DOC_ROOT+'art/portfolio/cat/'+cat, function(data) {
		$('#portfolio .main').html(data);
		$('#portfolio .main').show();
		$('#portfolio .detail').hide();
		fancyStart();
	});
}

function portfolio_details(id)
{
	$.get(DOC_ROOT+'art/portfolio/detail/'+id, function(data) {
		$('#portfolio .detail').html(data);
		$('#portfolio .detail').show();
		$('#portfolio .main').hide();
		fancyStart();
	});
}

function portfolio_back()
{
	$('#portfolio .main').show();
	$('#portfolio .detail').hide();
}

function scroller(a)
{
	if (a>0) d = '-=220'; else d = '+=220';
	$('#scrollers').animate({left:d},300,function(){portfolio_arrows();});
}

setContentStyle = function(style)
{
	$('#content').removeClass('red_content');
	$('#content').removeClass('black_content');
	$('#content').addClass(style+'_content');
	
	$('#footer').removeClass('red_footer');
	$('#footer').removeClass('black_footer');
	$('#footer').addClass(style+'_footer');
	
	if (style=='black')
		$('#body').css({backgroundColor: '#000000'});
	else
		$('#body').css({backgroundColor: '#cc0000'});
}

function f_page(url)
{
	page(url);
	return 'OK';
}

var appCache = {currentHash:'', history: new Array};
setInterval(
       function(){
           if (location.hash !== appCache.currentHash) {
				appCache.currentHash = location.hash;
				appCache.history.push(location.hash);
				url = location.hash.replace('#!','');
				page(DOC_ROOT +'art/'+ url, true);
				return true;
           }
           return false;
       }, 250
 );

function page(url, donot_history)
{
	if (!donot_history)
	{
		hash = url.replace(DOC_ROOT+'art/','');
		document.location = '#!'+hash;
		appCache.currentHash = location.hash;
		//Effect.ScrollTo('center', 100, {duration: 100});
	}
	$.get(url, function(data) {
		$('#center').html(data);
	});
	return false;
}
