/* JQUERY REQUIRED */

var scripts = document.getElementsByTagName("script");
eval( scripts[ scripts.length - 1 ].innerHTML );

;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);

(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);

$(document).ready(function(){

	var delay = 0;
	
	var def_holder = $("#default-holder");
	var def = $("#popupmenu .default");
	var def_li = $("#default_li");
	
	if (($.browser.msie && ($.browser.version == "6.0"))) {	
		$(".submenu-holder").bgiframe();
	}
	
	$("A.lvl-0").hover(function () {

		$("#pagelist .i").filter(".act").children(".innermenu").fadeOut(100);
		
		$(".subnav-1 LI A").removeClass("act");
		$('.submenu-holder').hide();
		$(this).parent().children('.submenu-holder').fadeIn(200);
		$(".subnav-1 LI").show();
		
		$(this).parent().parent().children("LI").children("A").removeClass("act");
		$(this).addClass("act");		

	}, function () { } );
	
	$("LI.lvl-0").hover( function () { clearTimeout(delay); }, function () { 
																		 
											delay = setTimeout(function () { 
																		 
												$(".lvl-0.act").removeClass("act");
												$(".subnav-1 LI A:not(.default)").parent().hide();
												$(def_li).show();
												$("#popupmenu .submenu-holder").hide();
												$(def_holder).show();
												if ($("#default").length == 1) {
													$("#default").addClass("act").parent().parent().parent().show();
													$(def_li).parent().show();
												} else {
													$("#default-holder .lev-last").hide();
												}
												$(def).addClass("act");

											}, 500); 
	});
	
	$("UL.open").hover(function () {
		
		var link_id = $(this).attr("id");
		link_id = link_id.substring(5);
		
		$("#link-"+link_id).addClass("act2");
		
	}, function () { 

		var link_id = $(this).attr("id");
		link_id = link_id.substring(5);
		
		$("#link-"+link_id).removeClass("act2");

	} );
	
	$("A.lvl-1").hover(function () {

		$(".default.lvl-1").removeClass("act");
		$("#default").removeClass("act");
		$(this).parent().parent().children("LI").show();
		
		if ($(this).parent().hasClass("has-sublevel")) {
			$(".lev-last").show();
		} else 
			$(".lev-last").hide();
		
		var index = $(this).attr("id");
		index = index.substring(5);

		$(".open").hide();
		$("#open-"+index).show().children("LI").show();
		
		$(this).parent().parent().children("LI").children("A").removeClass("act");
//		$(this).addClass("act3");
		
	}, function () { } );
	
	$("A.lvl-2").hover(function () {

		$(this).parent().parent().children("LI").show();

		var index = $(this).parent().parent().attr("id");
		index = index.substring(5);

		$(this).parent().parent().parent().parent().children("TD:first").children("UL").children("LI").show().children("A").filter(":not(#link-"+index+")").removeClass("act");
		
	}, function () { 
		
	});
	
	$("#cat_pg A").click(function () {
		
		var img = new Image();
		$("#pg_cat_loading").show();
		
		$(img).load( function () {
			$("#pg_cat_loading").hide();
			$("#pg_cat_preview").css("background-image", "url("+img.src+")");
		});
		
		img.src = BASE_HREF + $(this).attr("href");
		
		return false;
		
	});
	
	var page_delay = 0;
	
	$("#pagelist .i").hover( function () {

		if (!$(this).hasClass("act")) {
			$("#pagelist .i").removeClass("act").children(".innermenu").fadeOut(100);
		}

		clearTimeout(page_delay); 
		$(this).addClass("act").children(".innermenu").fadeIn(100);
		
									   
	}, function () {
	
		page_delay = setTimeout(function () { 

			$("#pagelist .i").filter(".act").children(".innermenu").fadeOut(100);
										  
		}, 1500);
			
	});
	
	$("#tab-list A").click( function () {
		
		var tabid = $(this).attr("href");
		action = tabid.substring(1, 5);
		tabid = tabid.substr(6);
		
		if (action == 'filt') {

			
			var t = $("#tab-list A.act").attr("href");
			$("#tab-list A").removeClass("act");
			$(this).addClass("act");

			$("#tab-1000 LI:not(.prodgroup-"+tabid+")").hide();
			$("#tab-1000 LI.prodgroup-"+tabid).fadeIn(300);
	
			if (t != '#show-1000') {
				if (t.substring(1, 5) != 'filt') {
					$(".tab").hide();
					$("#tab-1000").fadeIn(300);
				}
			}

		} else {

			if (tabid == 1000)
				$("#tab-1000 LI").css("visibility", "visible").fadeIn(300);

			$(".tab").hide();
			$("#tab-"+tabid).fadeIn(300);

		}
		
		$("#tab-list A").removeClass("act");
		$(this).addClass("act");
		
		return false;
		
	} );
	
	$("A[href='#']").attr("href", "javascript:void(0)");
	
	$("#btnPrint").click( function () { printpage() } );

	$(".hide_email").each(function () { 
									$(this).attr("href", "mailto:" + $(this).attr("name") + "@" + $(this).attr("title"))
										   .html($(this).attr("name") + "@" + $(this).attr("title")); });
	
	$(".param-change").change(function () {
										
		var variation = $(this).children(":selected").attr("title");
		
		//- su visai parametrais
		$(".param-change").each( function (index) {

			if ($(this).children(":selected").attr("title") != variation) {
				//- jei pasirinkta reiksme netinka
				var item_to_select = $(this).children("OPTION[title='"+variation+"']");
				
				var opts = $(this).children("OPTION");
				this.selectedIndex = ($(opts).index(item_to_select));
			}
										   
		});
		
		var item_to_select = $("#option").children("OPTION[value='"+variation+"']");
		var opts = $("#option").children("OPTION");

		document.getElementById('option').selectedIndex = ($(opts).index(item_to_select));
		$("#prod_code").html($(item_to_select).attr("title"));
		
		$("#option").change();

	});
	
	$("#printprod").click( function () {

		var url = document.location.href;

		for (i = url.length; i > 0; i--) {
			if (url[i] == '?') {
				url = url + '&';
				break;
			} else if ((url[i] == '/') || (url[i] == '\\')) {
				url = url + '?';
				break;
			}
		}

		if ($("#option").length > 0)
			var print_param = document.getElementById('option').selectedIndex;
		else			
			print_param = '';
			
		url += 'print=' + print_param;

		$(".param").each( function (index) {
					
			var n = $(this).attr("name");
			n = n.substring(6);
			var t = $(this);
							
			url += '&p_' + n + '=' + document.getElementById('param-'+n).selectedIndex;
									
		});

		document.location = url;
		
		return false;
		
	});

	$("#option").change(function () {
					
		var jsopt = $(this).children(":selected")
		var variation = $(jsopt).val();
		
		if ($(jsopt).attr("top") == 1) {
			$("#param_top").show();
			$("#i-b-top").fadeIn("fast");
		} else {
			$("#param_top").hide();
			$("#i-b-top").hide();
		}
		
		if ($(jsopt).attr("offer") == 1) {
			$("#param_offer").show();
			$("#i-b-offer").fadeIn("fast");
		} else {
			$("#param_offer").hide();
			$("#i-b-offer").hide();
		}
		
		if ($(jsopt).attr("sale") == 1) {
			$("#param_sale").show();
			$("#i-b-sale").fadeIn("fast");
		} else {
			$("#param_sale").hide();
			$("#i-b-sale").hide();
		}

		if ( ($(jsopt).attr("old_price") != 0) && ($(jsopt).attr("old_price") != "") ) {
			
			$("#old_price_title").show();
			$("#old_price").html( $(jsopt).attr("old_price") );
			$("#old_price_cont").show();
			
		} else {
			
			$("#old_price_title").hide();
			$("#old_price_cont").hide();
			
		}

		//- su visai parametrais
		$(".param-change").each( function (index) {

			if ($(this).children(":selected").attr("title") != variation) {
				//- jei pasirinkta reiksme netinka
				var item_to_select = $(this).children("OPTION[title='"+variation+"']");
				
				var opts = $(this).children("OPTION");
				this.selectedIndex = ($(opts).index(item_to_select));
			}
										   
		});
		
		/*var item_to_select = $("#option").children("OPTION[value='"+variation+"']");*/

		if (($(jsopt).attr("lang") != "") && ($(jsopt).attr("lang") != 0)) {
			$("#price_title").show();
			$("#price_cont").show();
		} else {
			$("#price_title").hide();
			$("#price_cont").hide();
		}
		
		$("#prod_code").html($(jsopt).attr("title"));		
		$("#prod_price").html($(jsopt).attr("lang"));
		
		$(".param").attr("lprice", "0");
		$(".param").change();

	});
	
	$(".param").change(function () {
		
		var price_diff = $(this).children(":selected").attr("title");
		var last_price = $(this).attr("lprice");
		if (last_price == undefined)  {
			last_price = '0';
		}
		$(this).attr("lprice", price_diff);
		
		changePrice($("#prod_price"), price_diff, last_price);

	});
	
	$("#openFrameCO").click( function () {
				
		var _h = $("#frameConsultationOrder").height();
		
		$("#orderConsultation").animate( { "height": _h }, 400 );
				
		$("#frameConsultationMenu").fadeOut(400, function () {
														   
			$("#frameConsultationOrder").fadeIn(400);
														   
		});
		
		return false;
									   
	});
	
	$("#openFrameCP").click( function () {
				
		var _h = $("#frameConsultationOrderPhone").height();
		
		$("#orderConsultation").animate( { "height": _h }, 400 );
				
		$("#frameConsultationMenu").fadeOut(400, function () {
														   
			$("#frameConsultationOrderPhone").fadeIn(400);
														   
		});
		
		return false;
									   
	});
	
	
	$("#btnCloseOrderCatalog").click(function () {
											   
		$("#orderCatalog").hide();
		
		return false;
		
	});
	
	$("#btnCloseConsultation").click(function () {

		$("#frameConsultationOrder").hide();
		$("#frameConsultationOrderPhone").hide();
		$("#orderConsultation").hide();
		$("#frameConsultationMenu").show();
		
		$("#orderConsultation").height(267);
		
		return false;
		
	});
	
	$("#btnOrderCatalog").click(function () {
		$("#orderConsultation").hide();
		if ($("#orderCatalog").css("display") == 'block')
			$("#orderCatalog").hide();
		else {
			
			if (($.browser.msie && ($.browser.version == "6.0")) && (MOD == 'eshop')) {
				
				$("#orderCatalog").css( { "left": $("#orderCatalog").width() / -2,
										  "top" : $(".settings:first").height() - 50 } ).show();
				
			} else {
			
				$("#orderCatalog").css( { "left": $("#orderCatalog").width() / -2,
										  "top" : $("#orderConsultation").height() / -2 - 50 } ).show();
			
			}
			
			$.scrollTo($("#orderCatalog").offset().top - 40, 400);
		}
		return false;
	});
	
	$("#btnOrderConsultation").click(function () {
		$("#orderCatalog").hide();
		if ($("#orderConsultation").css("display") == 'block')
			$("#orderConsultation").hide();
		else {
			
			if (($.browser.msie && ($.browser.version == "6.0")) && (MOD == 'eshop')) {


				$("#orderConsultation").css( { "left": $("#orderConsultation").width() / -2,
											   "top" : $(".settings:first").height() } ).show();

			} else {
				
				$("#orderConsultation").css( { "left": $("#orderConsultation").width() / -2,
											   "top" : $("#orderConsultation").height() / -2 } ).show();
			
			}
			
			$.scrollTo($("#orderConsultation").offset().top - 40, 400);
		}
		return false;
	});
	
	$("#formOrderCatalog").submit(function () {
		
		$(this).children("LABEL").removeClass("red");
		
		$.post('./ajax/order.php', { first_name : $("#first_name").val(),
									 last_name : $("#last_name").val(),
									 company : $("#company").val(),
									 notes : $("#notes").val(),
									 address : $("#address").val(),
									 city : $("#city").val(),
									 post_code : $("#post_code").val(),
									 phone : $("#phone").val(),
									 email : $("#email").val(),
									 order : 1,
									 lang : LANG },
				function (data) {

					$("#ajaxExec").html(data);
					
					
		});
		
		return false;
											
	});

	$("#formOrderConsultationPhone").submit(function () {
		
		$(this).children("LABEL").removeClass("red");

		$.post('ajax/consultation.php', { c_first_name : $("#cp_first_name").val(),
								 		  cp_call_time : $("#cp_call_time").val(),
									 	  c_phone : $("#cp_phone").val(),											
									 	  consultationByPhone : 1,
									 	  lang : LANG },
				function (data) {
					$("#ajaxExec").html(data);
				});
		
		return false;
											
	});
	
	$("#formOrderConsultation").submit(function () {
		
		$(this).children("LABEL").removeClass("red");

		$.post('ajax/consultation.php', { c_first_name : $("#c_first_name").val(),
											c_last_name : $("#c_last_name").val(),
											c_company : $("#c_company").val(),
									 		c_question_type : $("#c_question_type").val(),
									 		c_question : $("#c_question").val(),
									 		c_email : $("#c_email").val(),
									 		c_phone : $("#c_phone").val(),											
									 		consultation : 1,
									 		lang : LANG },
				function (data) {

					$("#ajaxExec").html(data);
					
		});
		
		return false;
											
	});
	
	$("#option").change();
	
});

function changePrice(id, diff, last_price) {
	
	var inp = $(id).html();
	if (inp == null) inp = '0';
	inp = inp.replace(',', '');
	inp = parseFloat(inp);

	if (last_price.charAt(0) == '-') {
		var t = Number($(id).html()) + Number(last_price.substring(1));
	} else if (diff.charAt(1) == '+') {
		var t = Number($(id).html()) - Number(last_price.substring(1));
	} else {
		var t = parseFloat(inp) - parseFloat(last_price);
	}

	if (diff.charAt(0) == '-') {
		var t = Number(t) - Number(diff.substring(1));
	} else if (diff.charAt(1) == '+') {
		var t = Number(t) + Number(diff.substring(1));
	} else {
		var t = parseFloat(Number(t)) + parseFloat(diff);
	}
	t = t.toString();
	
	if (-1 == t.indexOf('.')) t = t + '.00';
				  
	$(id).html(t.toString());		
}

function printpage() {
	var url = document.location.href;
	
	for (i = url.length; i > 0; i--) {
		if (url[i] == '?') {
			url = url + '&';
			break;
		} else if ((url[i] == '/') || (url[i] == '\\')) {
			url = url + '?';
			break;
		}
	} // pridet ? jei nera paramu, pridet & jei yra paramu

	win = window.open(url + 'do=print', 'popup', 'toolbar = 0, scrollbars = 1, status = 0');
	win.window.print();
}

