var Loader=
{
	_timeoutId:0,

	show: function()
	{
		Loader._timeoutId = setTimeout(Loader._showLoader, 1);

	//	Loader._showLoader();
	},

	hide: function()
	{
		clearTimeout( Loader._timeoutId );
		$('#load').addClass('displaynone');
		followRemove();
	},

	_showLoader: function()
	{
		followSet();
		$('#load').removeClass('displaynone');
	}
}





function submitShoppingCartAdd(sectionId, productId)
{
	Loader.show();
	
	if(typeof(productId)=='undefined')
		productId=0;

	fwajax.phpExecute(
			{url: '/cart/add'},
			sectionId,
			productId
		);
	
	return false;
}

function callbackShoppingCartAdd( num )
{
	var content = '<strong>' + num + '</strong> ';
	if (num == 0 || num > 4)
	{
		content += 'artikala';
	}
	if (num == 1)
	{
		content += 'artikl';
	}
	if (num > 1 && num < 5)
	{
		content += 'artikla';
	}
	
	//console.log($('.cart .quantity').html());
	$('.cart .quantity').html(content);
	
	/*
	if(success && html!='')
	{
		$('#cart_list').html(html);
	}
	
	Loader.hide();
	
	if(success)
	{
		if( $('#details_product_cart a').length )
		{
			$('#details_product_cart a').
				addClass('added').text(newMsg).
				animate( {opacity: 1.0}, 1500, function()
												{
													$('#details_product_cart a').
															removeClass('added').
															text(oldMsg);
												}
						);
		}
		
		if( $('#master_cart_add').length )
		{
			$('#master_cart_add').
				addClass('added').text(newMsg).
				animate( {opacity: 1.0}, 3500, function()
												{
													$('#master_cart_add').
															removeClass('added').
															text(oldMsg);
												}
						);
		}
		
	
		if( $('#list_product_cart_msg_'+sectionId+'_'+productId+' a').length )
		{
			$('#list_product_cart_msg_'+sectionId+'_'+productId+' a').
				addClass('added').html('<span>'+newMsg+'</span>').
				animate( {opacity: 1.0}, 1500, function()
											{
												$('#list_product_cart_msg_'+sectionId+'_'+productId+' a').
												removeClass('added').
												html('<span>' + oldMsg + '</span>');
											}
						);
		}
	}
	*/
}


function submitShoppingCartRemove(sectionId, productId)
{
	Loader.show();
	
	if(typeof(productId)=='undefined')
		productId=0;

	fwajax.phpExecute(
			{url: '/cart/remove'},
			sectionId,
			productId
		);
	
	return false;
}

function callbackShoppingCartRemove(success, sectionId, productId, html, total)
{
	if(success)
	{
		$('#cart_list').html(html);
		
		$('tr#cartitem_' + sectionId + '_' + productId).remove();
		$('#cart_table tr').removeClass('odd');
		$('#cart_table tr:nth-child(odd)').addClass('odd');
		
		callbackShoppingCartAdd(total);
	}
	
	//Loader.hide();
	
	if( $('table#cart_table tbody tr').length == 0 )
	{
		$('table#cart_table').css('display', 'none');
		$('#cart_empty').css('display', 'block');
		
		$('.only_cart_full').css('display', 'none');
	}
}


var _submitShoppingCartSetQuantityHandle=new Object;

function submitShoppingCartSetQuantity(sectionId, productId, diff)
{
	var obj=$('tr#cartitem_' + sectionId + '_' + productId + ' input[name^=cart_quantity]');
	
	var quantity=obj.val();
	quantity=parseInt(quantity);
	
	if(isNaN(quantity))
	{
		quantity=1;
	}
	
	obj.val(quantity);
		
	if(diff==0)
	{
		if( quantity == 0 )
		{
			submitShoppingCartRemove(sectionId, productId);
		}
		else
		{
			_submitShoppingCartSetQuantity(sectionId, productId, quantity);
			
		}
		
		return false;
	}

	if(diff>0)
		quantity++;
	else if(quantity>1 && diff<0)
		quantity--;
	else
		return false;

	obj.val(quantity);
	
	var keyix=sectionId + '_' + productId;
	
	if(typeof( _submitShoppingCartSetQuantityHandle[keyix] ) != 'undefined' )
	{
		clearTimeout(_submitShoppingCartSetQuantityHandle[keyix]);
		delete _submitShoppingCartSetQuantityHandle[keyix];
	}
	
	_submitShoppingCartSetQuantityHandle[keyix]=setTimeout('_submitShoppingCartSetQuantity('+sectionId+','+productId+','+quantity+')', 1000);
	
	return false;
}

function _submitShoppingCartSetQuantity(sectionId, productId, quantity)
{
	//alert( '('+sectionId+')('+productId+')('+quantity+')' );
	
	//console.log(quantity);
	
	var keyix=sectionId + '_' + productId;
	if(typeof( _submitShoppingCartSetQuantityHandle[keyix] ) != 'undefined' )
	{
		clearTimeout(_submitShoppingCartSetQuantityHandle[keyix]);
		delete _submitShoppingCartSetQuantityHandle[keyix];
	}
	
	//Loader.show();
	
	fwajax.phpExecute(
		{url: '/cart/quantity'},
		sectionId,
		productId,
		quantity
	);

	return false;
}

function callbackShoppingCartSetQuantity(success, sectionId, productId, quantity, html)
{
	Loader.hide();
	
	if(html)
	{
		$('#cart_list').html(html);
	}
}


function submitNewsletterEmailAdd()
{
	var str=$('#newsletter_email').val();
	
	if(!checkEmail(str))
	{
		$('#newsletter_container').addClass('error');
		return false;
	}

	var str2=$('#s_email').val();
	if(str2 != '')
	{
		return false;
	}
	
	Loader.show();
	$('#newsletter_container').removeClass('error');
	
	fwajax.phpExecute(
			{url: '/newsletter/email-add'},
			str,
			str2
		);
	
	return false;
}


function callbackNewsletterEmailAdd(success, popup, leadId)
{
	$('#newsletter_section_list input[type=checkbox]').attr('checked', 'checked');
	$('#lead_id').val('');
	
	Loader.hide();
	if(success)
	{
		$('#newsletter_container').removeClass('error');
		
		if(popup)
		{
			$('#lead_id').val(leadId);
			//alert('lead_id (' + leadId + ')(' + $('#lead_id').val() + ')' );
			
			tb_show('', $('#newsletter_prijava').attr('href'), false);
		}
	}
	else
	{
		$('#newsletter_container').addClass('error');
	}
}


function submitNewsletterSectionUpdate()
{
	var str=$('#newsletter_email').val();
	
	if(!checkEmail(str))
	{
		tb_remove();
		return false;
	}

	var str2=$('#s_email').val();
	if(str2 != '')
	{
		tb_remove();
		return false;
	}
	
	var lead_id=$('#lead_id').val();
	if(lead_id == '')
	{
		tb_remove();
		return false;
	}
	
	var section_1=$('#newsletter_section_list input[type=checkbox][name=section_1]').attr('checked') ? 1: 0;
	var section_2=$('#newsletter_section_list input[type=checkbox][name=section_2]').attr('checked') ? 1: 0;
	var section_3=$('#newsletter_section_list input[type=checkbox][name=section_3]').attr('checked') ? 1: 0;
	
	Loader.show();
	
	fwajax.phpExecute(
			{url: '/newsletter/section-update'},
			lead_id,
			str,
			str2,
			section_1,
			section_2,
			section_3
		);
	
	return false;
}


function callbackNewsletterSectionUpdate(success)
{
	Loader.hide();
	
	if(success)
	{
		$('#newsletter_email').val('');
	}
	
	tb_remove();
}











function setActiveTab(tab)
{
	$('#search_tab').val(tab);
	//$('#index_tab').val(tab);

	return true;
}






function onChangeArticleSubsection(selectDom)
{
	if(selectDom.selectedIndex==0)
	{
		location.href=$('#subsection_form').attr('action');
	}
	else
	{
		$('#subsection_form').submit();
	}
}





function checkEmail(value)
{
return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
}

//jquery specific styles
$(document).ready(function(){

	$(function(){
		// Tabs
		$('#tabs').tabs();
	});


	$('a.ext').attr('target', '_blank');



////////////////////////////////////////////////////////////////
//  Menu style fix start

//clasik top meni
	$(".nav_clasik a").mouseover(function(){

		var linkli=$(this).parent().not('.lang');
		
		linkli.prev().addClass("no_bar");		
		
	}).mouseout(function(){

		var linkli=$(this).not('.current').parent();

		linkli.prev().removeClass("no_bar");

	});


//current
	function currentMain()
	{
		var aobj=$('.nav_clasik a.current');
		if(aobj.length)
		{
			var linkli=aobj.parent();

			linkli.prev().addClass("no_bar");
		}
	}
	currentMain();




	

//second level meni
	$(".nav_sec a").mouseover(function(){

		var linkli=$(this).parent();

		linkli.prev().addClass("no_bar");
		//linkli.addClass("no_bar");

	}).mouseout(function(){

		var linkli=$(this).not('.current').parent();

		linkli.prev().removeClass("no_bar");
		//linkli.removeClass("no_bar");

	});


	//current
	function currentSec()
	{
		var aobj=$('.nav_sec a.current');
		if(aobj.length)
		{
			var linkli=aobj.parent();

			linkli.prev().addClass("no_bar");
			//linkli.addClass("no_bar");

		}
	}
	currentSec();
	
	//sub title
	function subTitle()
	{
		var aobj=$('.nav_sec span.title');
		if(aobj.length)
		{
			var linkli=aobj.parent();

			linkli.prev().addClass("no_bar");
			linkli.addClass("no_link");

		}
	}
	subTitle();


//  Menu style fix stop
////////////////////////////////////////////////////////////////





////////////////////////////////////////////////////////////////
// slider start

	if( $("#slider").length )
	{
		if( $("#autoslider").length )
		{
			$("#slider").easySlider( {
				auto:true,
				continuous: true,
				speed: 800,
				pause: 5000
			});
		}
		else
		{
			$("#slider").easySlider(
				{ continuous: true }
			);
		}
	
		
		$('#nextBtn a').stop().animate({ 
			opacity: 0.4
		  });
		
		$('#prevBtn a').stop().animate({ 
			opacity: 0.4
		  });
	
		
		$("#slider").mouseover(function(){
			$('#nextBtn a').stop().animate({ 
				opacity: 1
			  }, "fast" );
			
			$('#prevBtn a').stop().animate({ 
				opacity: 1
			  }, "fast" );
		}).mouseout(function(){
			$('#nextBtn a').stop().animate({ 
				opacity: 0.4
			  }, "fast" );
			
			$('#prevBtn a').stop().animate({ 
				opacity: 0.4
			  }, "fast" );
		});
		
		
		
		$('#slider .link').stop().animate({ 
			opacity: 0.6
		  });
		
		
		$("#slider").mouseover(function(){
			$('#slider .link').stop().animate({ 
				opacity: 1
			  }, "fast" );
		}).mouseout(function(){
			$('#slider .link').stop().animate({ 
				opacity: 0.4
			  }, "fast" );
		});
		
	}
	
	
	$(".slider_small").easySlider({
		auto:	false,		
		controlsShow: false
	});

	

// slider stop
////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////
//  Link style setup

	$('dl.download dd a[href$=".pdf"]').append("<span>pdf</span>");
	$('dl.download dd a[href$=".xdoc"]').append("<span>xdoc</span>");
	$('dl.download dd a[href$=".doc"]').append("<span>doc</span>");
	$('dl.download dd a[href$=".xml"]').append("<span>xml</span>");
	$('dl.download dd a[href$=".zip"]').append("<span>zip</span>");
	$('dl.download dd a[href$=".rar"]').append("<span>rar</span>");
	$('dl.download dd a[href$=".pps"]').append("<span>pps</span>");
	$('dl.download dd a[href$=".gif"]').append("<span>gif</span>");
	$('dl.download dd a[href$=".jpg"]').append("<span>jpg</span>");
	$('dl.download dd a[href$=".xls"]').append("<span>xls</span>");

//  Link style setup
////////////////////////////////////////////////////////////////

	$('.ref_title').click(function(){
	  $(this).next('.ref_list').slideToggle()
             .siblings('.ref_list:visible').slideUp();
	  $(this).toggleClass('rt_open ');
	  $(this).siblings().removeClass('rt_open ');
	});
	

// toggle reference table the advanced way
	var toggleMinus = '../images/ico/ico-table-minus.gif';
	var togglePlus = '../images/ico/ico-table-plus.gif';
	var $subHead = $('.reference_table tbody th:first-child');

	$subHead.prepend('<img src="' + togglePlus + '" alt="collapse this section" class="toggle_ico" />');

  	$('img', $subHead).addClass('clickable').click(function() {
	    var toggleSrc = $(this).attr('src');
		if ( toggleSrc == toggleMinus ) {
		  $(this).attr('src', togglePlus).parents('tr').siblings().addClass('collapsed').fadeOut('fast');
		} 
		else {
		  $(this).attr('src', toggleMinus).parents('tr').siblings().removeClass('collapsed').fadeIn('fast');
    };

  });
	
	

	$('.show_all').click(function(){
		$('.ref_list:hidden').slideDown();
		$('.ref_title').addClass('rt_open ');
		return false;
    });

	$('.close_all').click(function(){
		$('.ref_list:visible').slideUp();
		$('.ref_title').removeClass('rt_open ');
		return false;
    });


	$(".pager li").hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);
	

	$(".back_control p").hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);
	
	$("div#showreel_holder").easySlider({
		controlsShow: false,
		auto: true,
		continuous:true,
		pause: 	3000
		
	});
	
	$("p.full_cart a").hover(
	  function () {
		$(this).parent().parent().addClass("hover");
	  },
	   function () {
		$(this).parent().parent().removeClass("hover");
	  }
	);	
	

	//$("div#akcije_slides li:nth-child(1)").addClass("align");

	$(".meni_sidebar").find("li.current").prev("li").addClass("border_fix");


		$('.reference_nav ul').easyListSplitter({ 
			colNumber: 3,
			direction: 'horizontal' 

		});
		

	
// seperate reference nav into groups of 7

/*
	$(function() {
	  $(".reference_nav ul").each(function() {
		var list = $(this);
		var size = 7;
		var current_size = 0;
		list.children().each(function() {
		console.log(current_size + ": " + $(this).text());
		  if (++current_size > size) {
			var new_list = $("<ul></ul>").insertAfter(list);
			list = new_list;
			current_size = 1;
		  }
		  list.append(this);
		});
	  });
	});
*/



		
/*
	$("#index_text").bind('click', function() {
	  $('.search').animate({
		width: "394px"
	  }, 1000, function() {
		// Animation complete.
	  });
	  

	});

	$(".search input.button").bind('click', function() {
	  $('.search').animate({
		width: "145px"
	  }, 1000, function() {
		// Animation complete.
	  });
	});
*/


	$("a.form_toggle").bind('click', function() {
		$("#form_toggle").toggleClass("form_toggle_active");
		$("#cart_toggle").toggleClass("cart_toggle_active");
		//$.cookie("form_open", "foo");
		return false;
	  });
	
/*
	var view_State = $.cookie('form_open');

	if (view_State == 'foo') {
		$("#form_toggle").addClass("form_toggle_active");
		$("#cart_toggle").removeClass("cart_toggle_active");
	};
*/	

	$("#akcije_slides").easySlider({
		prevText: 'Previous Slide',
		nextText: 'Next Slide',
		auto: false,
		continuous:true,
		pause: 	10000
	});

//add class "last" to every third item in gallery list
	$("ul.gallery li:nth-child(3n)").addClass("last");
//add class "odd" to every odd tr reference table
	$(".reference_table tr:nth-child(odd)").addClass("odd");
//add class "odd" to every odd tr reference table
	$("#cart_table tr:nth-child(odd)").addClass("odd");
//add class "odd" to every odd tr reference table
	$("#cart_table tr:nth-child(odd)").addClass("odd");
//add class "last" to every third item in gallery list
	$("ul.color_palette li:nth-child(6n)").addClass("last");


//hover color palette RAL names
	$(".color_codes .color_palette li").mouseover(function(){
		$(this).children("span").clone().addClass("helper").appendTo(this);
		$("span.helper").topZIndex();
	});

	$(".color_codes .color_palette li").mouseout(function(){
		$(this).find("span.helper").detach();
	});


}); // end document ready



////////////////////////////////////////////////////////////////
//anchor slide start
/*******
*** Anchor Slider by Cedric Dugas ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it.
Don't forget to put an id to your anchor !
You can use and modify this script for any project you want, but please leave this comment as credit.
*****/

$(document).ready(function() {
 $("a.anchorLink").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 settings = jQuery.extend({
 speed : 1100
 }, settings);

 return this.each(function(){
 var caller = this
 $(caller).click(function (event) {
 event.preventDefault()
 var locationHref = window.location.href
 var elementClick = $(caller).attr("href")

 var destination = $(elementClick).offset().top;
 $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
 window.location.hash = elementClick
 });
 return false;
 })
 })
}

//anchor slide stop
////////////////////////////////////////////////////////////////


function startSmallSlider1 () {
	$("#ss1").easySlider({
		auto: true,
		controlsShow: false,
		continuous: true,
		pause:	4000
	});
}
function startSmallSlider2 () {
	$("#ss2").easySlider({
		auto: true,
		controlsShow: false,
		continuous: true,
		pause:	4000
	});
}
function startSmallSlider3 () {
	$("#ss3").easySlider({
		auto: true,
		controlsShow: false,
		continuous: true,
		pause:	4000
	});
}


$(window).load( function() {
	setTimeout( startSmallSlider1, 2100 );
	setTimeout( startSmallSlider2, 1800 );
	setTimeout( startSmallSlider3, 1500 );
});

