$(document).ready(function(){
	$("#loader2").hide();
	$("#loader3").hide();
	$("#loader4").hide();
   $('#d1').fadeOut().fadeIn().fadeOut().fadeIn();
   setTimeout("$('#d2').fadeOut().fadeIn().fadeOut().fadeIn()",1000);
   setTimeout("$('#d3').fadeOut().fadeIn().fadeOut().fadeIn()",2000);
   setTimeout("$('#d4').fadeOut().fadeIn().fadeOut().fadeIn()",3000);
   $('#d5').hide();
   $('#d5').slideToggle("slow");

});

function search_switch() {
   $("#search_top").hide();
   $("#search_advanced").slideToggle("fast");
}
function search_switch2() {
   $("#search_top").slideToggle("fast");
   $("#search_advanced").hide();
}
function zaloguj() {
	$("#logowanie_box").slideToggle("fast");
}

function zaloguj2() {
	$("#zalogowanie_box").slideToggle("fast");
}

function switch_news(a) {
   $("#xtc").load("/ajax/news.php?x="+a+"", function(){
		
	});
}
function koszyk() {
   $("#logowanie_box").hide();
	$("#koszyk_box").slideToggle("fast");
   $("#koszyk_content").load("/ajax/koszyk.php", function(){
		$("#koszyk_loader").hide();
	});
}
function optox() {
	$("#opto_dane").slideToggle();
}
function sax() {
	$("#dropz").slideToggle();
}
function step_2(dane,id_product,id_category) {
	$("#loader2").show();
   $("#kreator_top_1").css('background-image','url(/_img/lay/kr_d_2.png)'); 
   $("#box4content").html('');
   $("#box3content").html('');
  // $("#mytr"+dane+"").css('background-image','url(/_img/lay/box_1_tlo.png)'); 
	$("#box2content").load("/ajax/kreator.php", {technologia: dane,krok: 2,id_product: id_product,id_category: id_category}, function(){
		$("#loader2").hide();
	});
}
function modex(akcja) {
   if(akcja) {
      window.location = "/mode/"+akcja;
   }
}
function produktdelete()
{
	var ile = document.forms['koszyk_edit'].produkty.length;
	if(ile!=undefined)
	{
		var idstr = '';
		for(i=0;i<ile;i++)
		{
			if(document.forms['koszyk_edit'].produkty[i].checked)
			{
				if(i>0) idstr+=',';
				idstr+=document.forms['koszyk_edit'].produkty[i].value;
			}
		}
	}
	else
	{
		if(document.forms['koszyk_edit'].produkty.checked)
			idstr = document.forms['koszyk_edit'].produkty.value;
	}
	document.location='/zamowienie/delete/'+idstr;
}

function step_3(dane,id_product,id_technology,id_category) {
	$("#loader3").show();
   $("#kreator_top_1").css('background-image','url(/_img/lay/kr_d_3.png)'); 
   $("#box4content").html('');
   

   //$("#sytr"+dane+"").css('background-image','url(/_img/lay/box_2_tlo.png)');   
   
	$("#box3content").load("/ajax/kreator.php", {material: dane,krok: 3,id_product: id_product,id_technology: id_technology,id_category: id_category}, function(){
		$("#loader3").hide();
	});
}
function step_4(dane,id_product,id_technology,id_material,id_category) {
    
	$("#loader4").show();
   $("#kreator_top_1").css('background-image','url(/_img/lay/kr_d_4.png)'); 

	$("#box4content").load("/ajax/kreator.php", {cena: dane,krok: 4,id_product: id_product,id_technology: id_technology, id_material: id_material,id_category: id_category}, function(){
		$("#loader4").hide();
      $("#do_koszyka").hide();
	});
}

function roundVal(val){
	var dec = 2;
	var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


function get_price(dane) {

   var bazowa = $("input[@name='iloscsztuk']").getValue();
	var bazowa2 = $("#cenbig_hide").html();
	dane2 = bazowa2 * bazowa;   
   dane2 = roundVal(dane2);
   dane5 = roundVal(dane2);
   dane3 = "<img src=\"/_img/lay/dots15.png\" border=\"0\"> " + dane2 + " eur";
   dane4 = "" + dane5 + " eur";

   
	document.getElementById("cenbig").innerHTML = dane3;
   document.getElementById("cenbig3").innerHTML = dane4;
   $("#do_koszyka").show();
	/*
	if (bazowa == 1) {
		document.getElementById("cenbig").innerHTML = dane;
	} else if (bazowa > 1 && bazowa <10) {
		var modifier = 35.00;
		dane = bazowa * modifier;
		document.getElementById("cenbig").innerHTML = dane;
	} else if (bazowa > 10 && bazowa < 25) {
		var modifier = 33.00;
		dane = bazowa * modifier;
		document.getElementById("cenbig").innerHTML = dane;
	} else if (bazowa > 25 &&  bazowa < 50) {
		var modifier = 31.00;
		dane = bazowa * modifier;
		document.getElementById("cenbig").innerHTML = dane;
	} else {
		var modifier = 30.00;
		dane = bazowa * modifier;
		document.getElementById("cenbig").innerHTML = dane;
	}
	*/
	
}

function register_del_options() {
   $("#extra_register").css("display", "none");
   $("#extra_register2").css("display", "none");
   $("#extra_register3").css("display", "none");
}
function register_show_options() {
   $("#extra_register").css("display", "block");
}
function register_show_options_2() {

    var cfirma = $("input[@name='firmname']").getValue();
    $("input[@name='firmname_2']").setValue(cfirma);
    var cadres = $("input[@name='adres']").getValue();
    $("input[@name='adres_2']").setValue(cadres);
    var cnip = $("input[@name='nip']").getValue();
    $("input[@name='nip_2']").setValue(cnip);
    var ctelefon = $("input[@name='telefon']").getValue();
    $("input[@name='telefon_2']").setValue(ctelefon);
    
   $("#extra_register2").css("display", "block");
   $("#extra_register3").css("display", "none");
}
function register_show_options_3() {

    var cfirma = $("input[@name='firmname']").getValue();
    $("input[@name='firmname_2']").setValue(cfirma);
    var cadres = $("input[@name='adres']").getValue();
    $("input[@name='adres_2']").setValue(cadres);
    var cnip = $("input[@name='nip']").getValue();
    $("input[@name='nip_2']").setValue(cnip);
    var ctelefon = $("input[@name='telefon']").getValue();
    $("input[@name='telefon_2']").setValue(ctelefon);

   $("#extra_register2").css("display", "block");
   $("#extra_register3").css("display", "block");
}
jQuery(function( $ ){

$('#screen').serialScroll({
		target:'#sections',      
		items:'li', //selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',//selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',//selector to the 'next' button (absolute too)
		axis:'x',//the default is 'y'
		queue:false,//we scroll on both axes, scroll both at the same time.
		event:'click',//on which event to react (click is the default, you probably won't need to specify it)
		stop:false,//each click will stop any previous animations of the target. (false by default)
		lock:true, //ignore events if already animating (true by default)
		duration:400,//length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		start: 0, //on which element (index) to begin ( 0 is the default, redundant in this case )
		force:true, //force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		cycle:true,//cycle endlessly ( constant velocity, true is the default )
		step:1, //how many items to scroll each time ( 1 is the default, no need to specify )
		jump:false, //if true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		lazy:false,//(default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		interval:false, //it's the number of milliseconds to automatically go to the next
		navigation:'#navigation li a',
		constant:true,
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});

   
$('#screen3').serialScroll({
		target:'#sections3',      
		items:'li', //selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',//selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',//selector to the 'next' button (absolute too)
		axis:'x',//the default is 'y'
		queue:false,//we scroll on both axes, scroll both at the same time.
		event:'click',//on which event to react (click is the default, you probably won't need to specify it)
		stop:false,//each click will stop any previous animations of the target. (false by default)
		lock:true, //ignore events if already animating (true by default)
		duration:400,//length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		start: 0, //on which element (index) to begin ( 0 is the default, redundant in this case )
		force:true, //force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		cycle:true,//cycle endlessly ( constant velocity, true is the default )
		step:1, //how many items to scroll each time ( 1 is the default, no need to specify )
		jump:false, //if true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		lazy:false,//(default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		interval:false, //it's the number of milliseconds to automatically go to the next
		navigation:'#navigation3 li a',
		constant:true,
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
   
   
});


this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 40;
		yOffset = 15;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});


function produktcalculaterequest()
{
	var kategoria = document.forms['produkt_add'].kategoria.value;
	var item = document.forms['produkt_add'].item.value;
	var iloscsztuk = document.forms['produkt_add'].iloscsztuk.value;
	var ilosckolorow = document.forms['produkt_add'].ilosckolorow.value;
	var iloscmiejsc = document.forms['produkt_add'].iloscmiejsc.value;
	var itemnadruk = document.forms['produkt_add'].itemnadruk[document.forms['produkt_add'].itemnadruk.selectedIndex].value;
	var row_id = document.forms['produkt_add'].row_id.value;
	var pgnum = document.forms['produkt_add'].pgnum.value;
	var URL = '/kategoria/'+kategoria+'/item/'+item+'/przelicz/'+iloscsztuk+'/'+ilosckolorow+'/'+iloscmiejsc+'/'+itemnadruk+'/'+row_id+'/'+pgnum;
	document.location=URL;
}


