/**
 * 
 *   jQuery Pub Plugins
 *   Version 1.0
 *   Copyright (c) Nikolay Dutchuk, 2010
 * 
 */


/**
 * Enables to open all external links in a new window.
 */
this.externalLinks = function()
	{
		$("a[rel='external']").click(function()
			{
				window.open(this.href);
				return false;
			}
		);
	};


/**
 * Enables tab functionality.
 */
this.xtabs = function()
	{
		var xtabs = $("div#xtabs > div.xtab");
		var query = $.parseQuery().t;
		var tab   = (typeof(query) == "undefined" || query == "") ? 0 : query;
		
		$("div#xtabs ul.xtabnavi a").click(function() 
			{
				xtabs.hide().filter(this.hash).show();
				$("div#xtabs ul.xtabnavi a").removeClass("selected");
				$(this).addClass("selected");
				return false;
			}
		).filter(":eq(" + tab +  ")").click();
	};

	
/**
 * Enables dynamic loading of techdata.
 */
this.tdChooserForm = function()
	{
		$("form#tdchooser select").bind("change keyup keydown", function() 
			{
				$.post("data.techdata.php", { tid : this.value }, function(data){ $("div#xtab1 div").html(data) });
			}
		)
		.trigger("change");
	};

/**
 * Enables order form change for private/business customer.
 */
 this.isBusinessForm = function()
	{
		$("form#order select#isbusiness").bind("change keyup keydown", function()
			{
				if (this.value == 1)
				{
					$("dt#l1 label").html("Nosaukums:");
					$("dt#l3 label").html("Reģ. Nr.:");
					$("dt#l5 label").html("Juridiskā adrese:");
					
					$("dt#l2").show();
					$("dd#c2").show();
					$("dt#l4").show();
					$("dd#c4").show();
					$("dt#l7").show();
					$("dd#c7").show();
					$("dt#l8").show();
					$("dd#c8").show();
				}
				else
				{
					$("dt#l1 label").html("Vārds, uzvārds:");
					$("dt#l3 label").html("Personas kods:");
					$("dt#l5 label").html("Dzīvesvietas adrese:");

					$("dt#l2").hide();
					$("dd#c2").hide();
					$("dt#l4").hide();
					$("dd#c4").hide();
					$("dt#l7").hide();
					$("dd#c7").hide();
					$("dt#l8").hide();
					$("dd#c8").hide();
				}
			}
		)
		.trigger("change");
	};

	
/**
 * Loads all plugins.
 */
$().ready(function()
	{
		externalLinks();
		xtabs();
		tdChooserForm();
		isBusinessForm();
		
		$("ul#tabs li a").features(
			{
				output               : "ul#output li",
				start_item           : 2,
				transistion_interval : 10000
			}
		);		
		
		$("a.lightbox").lightBox(
			{
		    	imageLoading         : '../css/lightbox/loading.gif',
		    	imageBtnClose        : '../css/lightbox/close.gif',
		    	imageBtnPrev         : '../css/lightbox/prev.gif',
		    	imageBtnNext         : '../css/lightbox/next.gif',
		    	imageBlank           : '../css/lightbox/blank.gif',
		    	txtImage             : 'Attēls',
		    	txtOf                : 'no',
		    	containerResizeSpeed : 200
		    }
		);		
	}
);
