/*
 *		GLOBAL VARIABLES
 */
//materials
var materials_number = -1;
var materials_starting_number = 1;

//salon&kontakt
var image_count = -1;
var current_image = -1;
var switch_interval = null;

//uporabniki
var current_anketa = 1;
var anketa_count = 0;

//tshirt gallery
var current_gallery_item = 1;
var gallery_item_count = 0;

//user
var user_logged_in = false;
var user_info = {};
var user_auth = {};

//barvanje
var barvanje_polozaj = 1; // 0 = sedec, 1 = pollezec, 2 = lezec
var barvanje_slika = 1;
var barvanje_interval = null;

//slideshow
var number_of_slides = 0;
var current_slide = 1;
var slide_interval = null;
var slide_miliseconds = 4000;

//var basepath = "http://localhost/jabooz/";
var basepath = "http://www.udobje.com/";

$(document).ready(function() {
	// update listeners on page load
	updateListeners();
	
	// display actionResponse notification box
	displayActionNotification();
	
	// things that need to be done right on page load
	pageInitialization();
	
	/*
	 * 		INDEX PAGE SLIDESHOW
	 */
	number_of_slides = $(".slideButton").size();
	if(number_of_slides > 1) {	// at least 2 slides needed to slide
		slide_interval = new Interval(function() {
			$(".slideButton.active-slide").removeClass("active-slide");
			var id = $(".slideButton").eq(current_slide).addClass("active-slide").attr("id");
			$(".slide").fadeOut(500);
			$(".slide#" + id).fadeIn(500);
			current_slide++;
			if(current_slide >= number_of_slides)
				current_slide = 0;
		}, slide_miliseconds);
	}
	
	$(".slide, .slideButton").hover(function() {
		slide_interval.pause();
	}, function() {
		slide_interval.resume();
	});
	
	$(".slideButton").click(function(e) {
		e.preventDefault();
		if(!$(this).hasClass("active-slide")) {
			var remaining = $(this).nextAll(".slideButton").size();
			current_slide = number_of_slides - remaining;
			if(current_slide >= number_of_slides)
				current_slide = 0;
			var id = $(this).attr("id");
			$(".slideButton").removeClass("active-slide");
			$(this).addClass("active-slide");
			
			$(".slide").fadeOut(500);
			$(".slide#" + id).fadeIn(500);
		}
	});
	
	/*
	 *		FORMS
	 */
	
	//form submit link
	$(".form_submit_link").click(function(e) {
		e.preventDefault();
		
		var formId = $(this).attr("rel");
		var formHandle = $("form[rel=" + formId + "]");
		
		if(formHandle.length == 1) {
			if(validateForm(formHandle)) {
				formHandle.submit();
			} else {
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=form_error",
					success: function(data) {
						var response = eval('(' + data + ')');
						if(response != false) {
							showSimpleNotification("error", response['title'], response['text1'], null, function() {});
						}
					}
				});
			}
		}
	});
	
	$("input, textarea").keydown(function(e) {
		var form_handle = $(this).parents("form.submit_on_enter").eq(0);
		if(form_handle.size() > 0 && e.keyCode == 13 && validateForm(form_handle)) {
			var form_rel = form_handle.attr("rel");
			$("a[rel=" + form_rel + "]").trigger("click");
		}
	});
	
	/*
	 * 		MY PROFILE
	 */
	
	// change tabs
	/* SEE UPDATE LISTENERS */
	
	$(".jq_moj_profil_ostrani_naslov_link").click(function(e) {
		e.preventDefault();
		
		var address = $(this).attr("rel");
		var address_array = address.split("@");
		showYesNoNotification("normal", "Odstranim naslov?", "Želite res odstraniti naslov: <strong>" + address_array[1] + "</strong>", "Odstrani", "Prekliči", function() {
			$("#jq_moj_profil_odstrani_naslov_form_" + address_array[0]).submit();
		}, function() {});
	});
	
	
	/*
	 * 		IZDELEK
	 */
	
	//change tabs
	$(".link-izdelek-tab").click(function(e) {
		//prevent click
		e.preventDefault();
		
		//get required data
		var tabId = $(this).attr("rel");
		var ulHandle = $(this).parent().parent();
		
		//remove active-l element
		$(".active-l").remove();
		
		//change active-m and active-r to normal
		$(".active-m").removeClass("active-m").addClass("normal-l");
		$(".active-r").removeClass("active-r").addClass("normal-r");
		
		//transform clicked element into active 
		$(this).parent().before('<li class="active-l"><!-- --></li>');
		$(this).parent().removeClass("normal-l").addClass("active-m").css("opacity", "1");
		$(this).parent().next().removeClass("normal-r").addClass("active-r").css("opacity", "1");
		
		//switch content
		$("div.izdelek-tab-box").hide();
		$("div." + tabId).show();
	});
	
	
	
	//materials selection
	materials_number = $(".material-slika").length - 1;
	$(".izbran").html($(".material-slika.mat1").html());
	$(".izbran-plain").html($(".material-sklop.mat1").html());
	//initialize tshirt title
	$(".velikost_majice_value").html($(".velikost_majice_select").eq(0).val());
	
	//rotate left
	$(".material-rotate-left").click(function(e) {
		e.preventDefault();
		
		if(materials_number > 3) {
			if(materials_starting_number > 1) {
				//shift picture and stats right
				$(".material-slika.mat"+(materials_starting_number-2)).animate({"width": "117px"}, 500);
				$(".material-sklop.mat"+(materials_starting_number-2)).animate({"width": "117px"}, 500);
				materials_starting_number--;
				
				//disable or enable arrows
				if(materials_starting_number == 1)
					$(this).addClass("inactive");
				else
					$(this).removeClass("inactive");
				if(materials_starting_number == materials_number -2)
					$(".material-rotate-right").addClass("inactive");
				else
					$(".material-rotate-right").removeClass("inactive");
			}
		}
	});
	
	//rotate right
	$(".material-rotate-right").click(function(e) {
		e.preventDefault();
		
		if(materials_number > 3) {
			if(materials_starting_number < materials_number - 2) {
				//shift picture and stats left
				$(".material-slika.mat"+(materials_starting_number-1)).animate({"width": "0px"}, 500).addClass("box_hidden");
				$(".material-sklop.mat"+(materials_starting_number-1)).animate({"width": "0px"}, 500).addClass("box_hidden");
				materials_starting_number++;
				
				//disable or enable arrows
				if(materials_starting_number == materials_number -2)
					$(this).addClass("inactive");
				else
					$(this).removeClass("inactive");
				if(materials_starting_number == 1)
					$(".material-rotate-left").addClass("inactive");
				else
					$(".material-rotate-left").removeClass("inactive");
			}		
		}
		
		
	});
	
	//material selection
	$(".material-slika").click(function(e) {
		e.preventDefault();
	
		//switch selected item
		$(".izbran").html($(this).html());
		var mat = $(this).attr("class");
		var mat_array = mat.split(" ");
		$(".izbran-plain").html($(".material-sklop." + mat_array[1]).html());
		
		//switch material color box
		$(".barve_materiala").hide();
		$(".barve_materiala." + mat_array[1]).show();
		
		if(!$(this).hasClass("type_napis")) {
			//switch price value
			$(".product-price").hide();
			$(".product-price." + mat_array[1]).show();
			
			//switch material opis
			$(".opis_materiala").hide();
			$(".opis_materiala." + mat_array[1]).show();
			//switch material ime
			$(".ime_materiala").hide();
			$(".ime_materiala." + mat_array[1]).show();
			
			/* is this useless?
			//change tshirt size title
			$("div.velikost_majice:visible").children().eq(0).trigger("change");
			*/
		
			//change materialid in session cookie
			var materialid_value = mat_array[2].substring(2);
			$.post(basepath + "actions/ajax.php", {action: "session_update_material_color", materialid: materialid_value});
		} else {
			//change inscriptionid in session cookie
			var inscriptionid_value = mat_array[2].substring(2);
			$.post(basepath + "actions/ajax.php", {action: "session_update_inscription", inscriptionid: inscriptionid_value});
			
			//switch napis ime
			$(".ime_napisa").hide();
			$(".ime_napisa." + mat_array[1]).show();
			
			//fetch initial garment stock
			$(".velikost_majice_select").eq(0).trigger("change");
		}
		
		//change material color image & fetch stock
		$(".barve_materiala." + mat_array[1]).children().eq(0).trigger("click");
	});
	
	//show more material description
	$(".material_opis_vec_link").click(function(e) {
		e.preventDefault();
		
		//hide short desc and show longer one
		$(this).parent().slideToggle();
		$(this).parent().prev().slideToggle();
	});
	
	//hide material description
	$(".material_opis_manj_link").click(function(e) {
		e.preventDefault();
		
		//hide long desc and show shorter one
		$(this).parent().slideToggle();
		$(this).parent().next().slideToggle();
	});
	
	//change material color
	$(".majice-barva").click(function(e) {
		e.preventDefault();
		$(".majice-barva").removeClass("active");
		$(this).addClass('active');
		
		//get color id
		var classes = $(this).attr("class");
		var class_arr = classes.split(" ");
		var colorid = class_arr[1].substring(5);
		var size_value = $(".velikost_majice_select").eq(0).val();
		
		var data_value = "action=fetch_material_color_image_or_gallery&cid=" + colorid;
		if(size_value != undefined)
			data_value += "&size=" + size_value;
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: data_value,
			async: false,
			success: function(data) {
				if(data != "0") {
					var data_array = data.split("@@");
					$(".pregled-slike-holder").html(data_array[0]);
					$(".ime_barve").hide();
					$(".ime_barve.barva" + colorid).show();
					
					if(data_array[1] <= 10)
						$("#zaloga_kolicina").html(data_array[1]);
					else
						$("#zaloga_kolicina").html(">10");
					
					switch(parseInt(data_array[2])) {
						case 1: $("#zaloga_cas_dobave").html("1-2 dni"); $("#zaloga_cas_dobave_tekst").html("[na zalogi]"); break;
						case 2: $("#zaloga_cas_dobave").html("5-14 dni"); $("#zaloga_cas_dobave_tekst").html("[v izdelavi]"); break;
						case 3: $("#zaloga_cas_dobave").html("14-45 dni"); $("#zaloga_cas_dobave_tekst").html("[ni na zalogi]"); break;
					}
				}
				gallery_item_count = $(".pregled-slike-holder").find(".pregled-slikica").size() + $(".pregled-slike-holder").find(".pregled-slikica-active").size();
				updateListeners();
				$(".pregled-slike-holder").find(".pregled-slikica").first().removeClass("pregled-slikica").addClass("pregled-slikica-active");
			}
		});
	});
	
/*	$(".majice-barva").click(function(e) {
		e.preventDefault();
		
		//get color id
		var classes = $(this).attr("class");
		var class_arr = classes.split(" ");
		var colorid = class_arr[1].substring(5);
		var size_value = $(".velikost_majice_select").eq(0).val();
		
		var data_value = "action=fetch_material_color_image_or_gallery&cid=" + colorid;
		if(size_value != undefined)
			data_value += "&size=" + size_value;
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: data_value,
			async: false,
			success: function(data) {
				if(data != "0") {
					var data_array = data.split("@@");
					$(".pregled-slike-holder").html(data_array[0]);
					$(".ime_barve").hide();
					$(".ime_barve.barva" + colorid).show();
					
					if(data_array[1] <= 10)
						$("#zaloga_kolicina").html(data_array[1]);
					else
						$("#zaloga_kolicina").html(">10");
					
					switch(parseInt(data_array[2])) {
						case 1: $("#zaloga_cas_dobave").html("1-2 dni"); $("#zaloga_cas_dobave_tekst").html("[na zalogi]"); break;
						case 2: $("#zaloga_cas_dobave").html("5-14 dni"); $("#zaloga_cas_dobave_tekst").html("[v izdelavi]"); break;
						case 3: $("#zaloga_cas_dobave").html("14-45 dni"); $("#zaloga_cas_dobave_tekst").html("[ni na zalogi]"); break;
					}
				}
				
				gallery_item_count = $(".pregled-slike-holder").find(".pregled-slikica").size() + $(".pregled-slike-holder").find(".pregled-slikica-active").size();
				updateListeners();
				$(".pregled-slike-holder").find(".pregled-slikica").first().removeClass("pregled-slikica").addClass("pregled-slikica-active");
			}
		});
	});*/
	
	//change tshirt size
	$(".velikost_majice_select").change(function() {
		var size_value = $(this).val();
		var size_value_text = $(".velikost_majice_select option[value='" + size_value + "']").text();
		
		$(".velikost_majice_value").html(size_value_text);
		
		$.post(basepath + "actions/ajax.php", {action: "fetch_garment_stock", size: size_value}, function(data) {
			if(data != "0") {
				var data_array = data.split("@@");
		
				if(data_array[0] <= 10)
					$("#zaloga_kolicina").html(data_array[0]);
				else
					$("#zaloga_kolicina").html(">10");
				
				switch(parseInt(data_array[1])) {
					case 1: $("#zaloga_cas_dobave").html("1-2 dni"); $("#zaloga_cas_dobave_tekst").html("[na zalogi]"); break;
					case 2: $("#zaloga_cas_dobave").html("5-14 dni"); $("#zaloga_cas_dobave_tekst").html("[v izdelavi]"); break;
					case 3: $("#zaloga_cas_dobave").html("14-45 dni"); $("#zaloga_cas_dobave_tekst").html("[ni na zalogi]"); break;
				}
			}
		});
	});
	
	// show notification for more information on stock and delivery
	$(".show_stock_information_notification").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=stock_delivery_info",
			success: function(data) {
				var response = eval('(' + data + ')');
				if(response != false) {
					showSimpleNotification("success", response['title'], response['text1'], null, function() {});
				}
			}
		});
	});
	
	// MATERIAL INITIALIZATION
	
	if($("#product_info_ids").size() > 0) {	// load, where material and other ids are given
		var m = $("#product_info_materialid").html();
		var c = $("#product_info_colorid").html();
		if($("#product_info_inscriptionid").size() > 0) {
			var m = $("#product_info_inscriptionid").html();
			var s = $("#product_info_materialid").html();
		}
		
		$(".material-slika.id" + m).trigger("click");
		$(".majice-barva.color" + c).trigger("click");
		if($("#product_info_inscriptionid").size() > 0) {
			$(".velikost_majice_select").val(s).trigger("change");
		}
		
		// if user clicked add to cart in his e-mail message, then add this product to cart
		if($("#product_info_add_to_cart").size() > 0) {
			setTimeout(function() { $(".dodaj_izdelek_v_kosarico").trigger("click"); }, 1000);
		}
	} else { // normal load
		//on page load prepare first material image & count images
		$(".majice-barva").eq(0).trigger("click");
		//fetch initial garment stock
		$(".velikost_majice_select").eq(0).trigger("change");
	}
	
	$(".jq_what_is_wish_list").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=what_is_wish_list",
			success: function(data) {
				var response = eval('(' + data + ')');
				if(response != false) {
					showSimpleNotification("normal", response['title'], response['text1'], null, function() {});
				}
			}
		});
	});
	
	//tshirt gallery right
		/**
		 * 	SEE UPDATE_LISTENERS: TSHIRT_GALLERY_RIGHT
		 */
	//tshirt gallery left
		/**
		 *  SEE UPDATE_LISTENERS: TSHIRT_GALLERY_LEFT
		 */
	//tshirt gallery select
		/**
		 *  SEE UPDATE_LISTENERS: TSHIRT_GALLERY_SELECT
		 */
	
	/** FAQ MODULES **/
	
	//switch FAQ modules
	$(".change_faq_module").click(function(e) {
		e.preventDefault();
		
		//switch active class
		$(".faq_module").removeClass("active");
		$(this).parent().addClass("active");
		
		//hide both first and last spacer
		$(".spacer.first").hide();
		$(".spacer.last").hide();
		
		//hide or show first/last spacer
		if($(this).parent().prev().hasClass("first"))
			$(this).parent().prev().show();
		if($(this).parent().next().hasClass("last"))
			$(this).parent().next().show();
		
		//change faq content
		var class_string = $(this).attr("class");
		var class_string_arr = class_string.split(" ");
	
		$(".faq_content").hide();
		$(".faq_content." + class_string_arr[1]).show();
		
		$(".prikazi-vsa").removeClass("hide").addClass("show").html("Prikaži vse odgovore").attr("title", "Prikaži vse odgovore");
	});
	
	//show all answers
	$(".prikazi-vsa-faq").click(function(e) {
		e.preventDefault();
		
		var mode = 0;	//0 == show answers, 1 == hide answers
		if($(this).hasClass("show")) {
			mode = 0;
			$(this).removeClass("show").addClass("hide");
			$(this).html("Skrij vse odgovore").attr("title", "Skrij vse odgovore");
		} else {
			mode = 1;
			$(this).removeClass("hide").addClass("show");
			$(this).html("Prikaži vse odgovore").attr("title", "Prikaži vse odgovore");
		}
		
		//slide answer boxes
		$(this).nextAll(".faq_content:visible").find("div.odgovor").each(function() {
			if(mode == 0)
				$(this).slideDown();
			else
				$(this).slideUp();
		});
		
		//update links
		$(this).next().find("div.vprasanje").each(function() {
			$(this).find("a.prikazi-odgovor").each(function() {
				if(mode == 0) {
					$(this).html("Skrij odgovor");
					$(this).attr("title", "Skrij odgovor");
				} else {
					$(this).html("Prikaži odgovor");
					$(this).attr("title", "Prikaži odgovor");	
				}
			});
		});
	});
	
	//show single answer
	$(".salon_skrij_odgovor").click(function(e) {
		e.preventDefault();
		
		if($(this).html() == "Prikaži odgovor") {
			$(this).html("Skrij odgovor");
			$(this).attr("title", "Skrij odgovor");
		} else {
			$(this).html("Prikaži odgovor");
			$(this).attr("title", "Prikaži odgovor");
		}
		
		$(this).parent().next().slideToggle();
	});
	
	//show single answer
	$(".prikazi-odgovor").click(function(e) {
		e.preventDefault();
		
		if($(this).html() == "Prikaži odgovor") {
			$(this).html("Skrij odgovor");
			$(this).attr("title", "Skrij odgovor");
		} else {
			$(this).html("Prikaži odgovor");
			$(this).attr("title", "Prikaži odgovor");
		}
		
		$(this).parent().next().slideToggle();
	});
	
	/** INSTRUCTIONS **/
	
	//show/hide single instruction block
	$(".pokazi-navodilo").click(function(e) {
		e.preventDefault();
		
		// hide all instructions
		$(".navodilo").slideUp();
		
		$(this).parent().parent().find("li").each(function() {
			if($(this).hasClass("menu-item"))
				$(this).removeClass("active");
		});
		$(".spacer.first").hide();
		$(".spacer.last").hide();
		
		$(this).parent().addClass("active");
		
		//hide or show first/last spacer
		if($(this).parent().prev().hasClass("first")) {
			$(this).parent().prev().hide();
		}
		if($(this).parent().next().hasClass("last")) {
			$(this).parent().next().hide();
		}
		
		//show/hide instruction block
		var class_string = $(this).attr("class");
		var class_string_arr = class_string.split(" ");
	
		$(".navodilo." + class_string_arr[1]).slideToggle();
		
		/*
		//determine state of this block
		var state = -1;	//state = 0 => currently inactive, state = 1 => currently active
		if($(this).parent().hasClass("active")) {
			state = 1;
			$(this).parent().removeClass("active");
		} else {
			state = 0;
			$(this).parent().addClass("active");
		}
		
		//hide both first and last spacer
		$(".spacer.first").hide();
		$(".spacer.last").hide();
		
		//hide or show first/last spacer
		if($(this).parent().prev().hasClass("first")) {
			if(state == 0)
				$(this).parent().prev().show();
			else
				$(this).parent().prev().hide();
		}
		if($(this).parent().next().hasClass("last")) {
			if(state == 0)
				$(this).parent().next().show();
			else
				$(this).parent().next().hide();
		}
		
		//show/hide instruction block
		var class_string = $(this).attr("class");
		var class_string_arr = class_string.split(" ");
	
		$(".navodilo." + class_string_arr[1]).slideToggle();	
		
		*/
	});
	
	//show hide all instruction blocks
	$(".prikazi-vsa-navodila").click(function(e) {
		e.preventDefault();
		
		var action = "";
		if($(this).hasClass("hide")) {
			$(this).removeClass("hide").addClass("show").attr("title", "Prikaži navodila").html("Prikaži navodila");
			action = "hide";
		} else {
			$(this).removeClass("show").addClass("hide").attr("title", "Skrij navodila").html("Skrij navodila");
			action = "show";
		}
		
		//slide answer boxes
		var menu_handle = $(this).parent().next().children("find");
		
		if(action == "hide") {
			$(".navodilo").slideUp();
			
			$(this).parent().next().find("li").each(function() {
				if($(this).hasClass("menu-item"))
					$(this).removeClass("active");
			});
			$(".spacer.first").hide();
			$(".spacer.last").hide();
		} else {
			$(".navodilo").slideDown();
			
			$(this).parent().next().find("li").each(function() {
				if($(this).hasClass("menu-item"))
					$(this).addClass("active");
			});
			$(".spacer.first").show();
			$(".spacer.last").show();
		}
	});
	
	//change subinstruction tab
	$(".change-instruction-tab").click(function(e) {
		e.preventDefault(); 
		
		//show/hide instruction block
		var class_string = $(this).attr("class");
		var class_string_arr = class_string.split(" ");
		var parent_handle = $(this).parent().parent();
		
		//switch tab content
		parent_handle.nextAll("div.navodilo-vsebina").fadeOut(300);
		setTimeout(function() { 
			parent_handle.nextAll("div.navodilo-vsebina." + class_string_arr[1]).fadeIn(300); 
		}, 300);

		//switch button active state
		
		//remove active-l element
		parent_handle.children(".navodilo-z-active-l").remove();
		
		//change active-m and active-r to normal
		parent_handle.children(".navodilo-z-active-m").removeClass("navodilo-z-active-m").addClass("navodilo-z-l");
		parent_handle.children(".navodilo-z-active-r").removeClass("navodilo-z-active-r").addClass("navodilo-z-r");
		
		//transform clicked element into active 
		$(this).parent().before('<div class="navodilo-z-active-l"><!-- --></div>');
		$(this).parent().removeClass("navodilo-z-l").addClass("navodilo-z-active-m");
		$(this).parent().next().removeClass("navodilo-z-r").addClass("navodilo-z-active-r");
	});
	
	/*
	 * 		SALON IN KONTAKT
	 */
	
	//automatically switch images
	image_count = $(".kvad").size() + 1;
	current_image = 0;
	
	if(image_count > 1) {
		switch_interval = setInterval('switchImage(current_image, image_count)', 3000);
	}
	
	$(".use-kvad").click(function(e) {
		e.preventDefault();
		
		//get image id from class
		var classes = $(this).attr("class");
		var class_array = classes.split(" ");
		var next_image = class_array[0].substring(5);
		
		//clear interval
		clearInterval(switch_interval);
		
		//change active square
		$(".kvad-active").removeClass("kvad-active").addClass("kvad");
		$(".kvad.slika" + next_image).removeClass("kvad").addClass("kvad-active");
		
		//change acitve image
		$(".image.slika" + current_image).fadeOut(500);
		$(".image.slika" + next_image).fadeIn(500);
		
		//set new interval and update current image
		current_image = next_image;
		switch_interval = setInterval('switchImage(current_image, image_count)', 3000);
	});
	
	/*
	 * 		UPORABNIKI
	 */
	
	anketa_count = $(".anketa-image").size();
	if(anketa_count <= 1) {
		$(".mnenja-arrow-right").hide();
	}
	
	$(".change-mnenja-tab").click(function(e) {
		e.preventDefault();
		
		var classes = $(this).attr("class");
		var class_array = classes.split(" ");
		
		$(".mnenja-button").removeClass("mnenja-active");
		if($(this).hasClass("mnenja-button"))
			$(this).addClass("mnenja-active");
		else
			$(this).parent().addClass("mnenja-active");
		
		$(".mnenja-tab").hide();
		$(".mnenja-tab." + class_array[1]).show();
	});
	
	//next image (right)
	$(".mnenja-arrow-right").click(function(e) {
		e.preventDefault();
		
		current_anketa++;
		//calculate left pixels
		var pixels = (current_anketa - 1) * 680;
		
		$(".ankete-inner").animate({left: "-" + pixels + "px"}, 500);
		
		//hide right button if at end
		if(current_anketa == anketa_count) {
			$(".mnenja-arrow-right").hide();
		}
		$(".mnenja-arrow-left").show();
	});
	
	//previous image (left)
	$(".mnenja-arrow-left").click(function(e) {
		e.preventDefault();
		
		current_anketa--;
		//calculate left pixels
		var pixels = (current_anketa - 1) * 680;
		
		$(".ankete-inner").animate({left: "-" + pixels + "px"}, 500);
		
		//hide right button if at end
		if(current_anketa == 1) {
			$(".mnenja-arrow-left").hide();
		}
		$(".mnenja-arrow-right").show();
	});
	
	/*
	 * 	KOŠARICA
	 */
	
	// add product to shopping cart
	$(".dodaj_izdelek_v_kosarico").click(function(e) {
		e.preventDefault();
		
		var productID = $(this).attr("id");
		
		$.post(basepath + "actions/ajax.php", {action: "add_product_to_shopping_cart", pid: productID}, function(data) {
			var response = eval('(' + data + ')');
			
			updateQtyString();
			evaluate_actions(false);
			
			// display notifications
			if(response['type'] == 1) {	// user added a new product
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_product_to_cart_success",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + "<br />" +
								"Model: <strong>" + response['product_info']['product'] + "</strong><br />" +
								"Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							if(response['product_info']['inscription'] != null) {
								message_body += "Napis: <strong>" + response['product_info']['inscription'] + "</strong><br />" +
									"Velikost: <strong>" + response['product_info']['size'] + "</strong><br />";
							}
							message_body += "<br />V nakupovalnem vozičku imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";
							
							showSimpleNotification("success", notification['title'], message_body, "<a href='kosarica/nakupovalni-vozicek' title='Pregled vsebine nakupovalnega vozička'>V nakupovalni voziček</a>", function() {});
						}
					}
				});
			} else if(response['type'] == 2) {	// user added a product that already exists in cart
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_product_to_cart_already_in",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + "<strong>Opozorilo: </strong>" + notification['text2'] +
								"Model: <strong>" + response['product_info']['product'] + "</strong><br />" +
								"Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							if(response['product_info']['inscription'] != null) {
								message_body += "Napis: <strong>" + response['product_info']['inscription'] + "</strong><br />" +
									"Velikost: <strong>" + response['product_info']['size'] + "</strong><br />";
							}
							message_body += "<br />V nakupovalnem vozičku imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";
							showSimpleNotification("normal", notification['title'], message_body, "<a href='kosarica/nakupovalni-vozicek' title='Pregled vsebine nakupovalnega vozička'>V nakupovalni voziček</a>", function() {});
						}
					}
				});
			}
		});
		
		/*$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=evaluate_actions",
			success: function(data) {
			}
		});*/
		
		
	});
	
	$(".odstrani_izdelek_iz_kosarice").click(function(e) {
		e.preventDefault();
		
		var productID = $(this).attr("id");
		var product_handle = $(this).parents(".leftbox").eq(0);
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=odstrani_izdelek_iz_kosarice",
			success: function(data) {
				var notification = eval('(' + data + ')');
				if(notification != false) {
					showYesNoNotification("normal", notification['title'], notification['text1'], notification['button_yes'], notification['button_no'], function() {
						$.post(basepath + "actions/ajax.php", {action: "remove_product_from_shopping_cart", pid: productID}, function(data) {
							if(data == "1") {
								product_handle.slideUp("fast", function() {
									product_handle.remove();
								});
								
								updateQtyString();
								evaluate_actions(true);
							}
						});
					}, function() {});
				}
			}
		});
		
		/*$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=evaluate_actions",
			success: function(data) {
			}
		});*/
		
		
	});
	$(".odstrani_vse_izdelke").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=odstrani_vse_izdelke_iz_kosarice",
			success: function(data) {
				var notification = eval('(' + data + ')');
				if(notification != false) {
					showYesNoNotification("normal", notification['title'], notification['text1'], notification['button_yes'], notification['button_no'], function() {
						$.post(basepath + "actions/ajax.php", {action: "remove_all_products_from_shopping_cart"}, function(data) {
							if(data == "1") {
								$(".leftbox").slideUp("fast", function() {
									$(".leftbox").remove();
									location.reload();
								});
							}
						});
					}, function() {});
				}
			}
		});
		
		updateQtyString();
	});
	$(".refresh_item_price").click(function(e) {
		e.preventDefault();
		
		// update all prices
		updatePrices(1, true);
	});
	
	// DARILNI BON
	$(".preveri_stanje_darilnega_bona").click(function(e) {
		e.preventDefault();
		
		$(".stanje_darilnega_bona").slideToggle();
	});
	$("#preveri_darilni_bon").click(function() {
		var code_value = $("#koda_darilnega_bona").val();
		$("#koda_darilnega_bona").attr("readonly", "readonly");
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: "action=check_voucher_code&code=" + code_value,
			async: false,
			success: function(data) {
				var data_array = data.split("@");
				if(data_array[0] == "-1") {
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=darilni_bon_ne_obstaja",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								showSimpleNotification("error", notification['title'], notification['text1'], null, function() {
									$("#koda_darilnega_bona").attr("readonly", "").val("");
								});
							}
						}
					});
				} else if(data_array[0] == "0") {
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=darilni_bon_porabljen",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								showSimpleNotification("error", notification['title'], notification['text1'] + data_array[2] + ".", null, function() {
									$("#koda_darilnega_bona").attr("readonly", "").val("");
								});
							}
						}
					});
				} else if(data_array[0] == "1") {
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=darilni_bon_veljaven",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								showYesNoNotification("success", notification['title'], notification['text1'].replace("[xxxx]", data_array[1]), notification['button_yes'], notification['button_no'], function() {
									$.ajax({
										url: basepath + "actions/ajax.php",
										type: "POST",
										async: false,
										data: "action=add_voucher_to_cart&code=" + code_value,
										success: function(add_response) {
											if(add_response == "1")
												location.reload();
											else
												$("#koda_darilnega_bona").attr("readonly", "").val("");
										}
									});
								}, function() {
									$("#koda_darilnega_bona").attr("readonly", "").val("");
								});
							}
						}
					});
				} else if(data_array[0] == "2") {
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=darilni_bon_ze_v_kosarici",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								showSimpleNotification("normal", notification['title'], notification['text1'], null, function() {
									$("#koda_darilnega_bona").attr("readonly", "").val("");
								});
							}
						}
					});
				}
			}
		});
	});
	
	// before continuing to step 2, update prices
	$(".step1_next").click(function() {
		updatePrices(1, false);
	});
	
	/* STEP 3 */
	$(".shop_select_address").change(function() {
		var address_id = $(this).val();
		$("#input_addressid").val(address_id);
		
		$(".naslov-right").hide("fast");
		$("#address_right_" + address_id).show("fast");
	});
	// edit address
	$(".address_edit").click(function(e) {
		e.preventDefault();
		
		if($(this).next().is(":visible")) {
			$(this).next().hide("fast");
			$(this).next().next().show("fast");
		} else {
			$(this).next().show("fast");
			$(this).next().next().hide("fast");
		}
	});
	// add new address
	$(".address_add_link").click(function(e) {
		e.preventDefault();
		
		$(".naslov-right").hide("fast");
		$("#address_new").show("fast");
	});
	
	// hide/show add address form in my profile section
	$("#jq_moj_profil_dodaj_naslov_link").click(function(e) {
		e.preventDefault();
		
		$("#jq_moj_profil_dodaj_naslov").slideToggle();
	});
	
	// show step 3 next button on radio selected
	$(".radio_dostava").change(function() {
		$("#input_nacin_dostave").val($(this).val());
		
		if($("#jq_kosarica_kontaktni_telefon").size() > 0) {
			if($("#jq_kosarica_kontaktni_telefon").not(":visible")) {
				$("#jq_kosarica_kontaktni_telefon").slideDown();
			}
		} else {
			if($("#step3_next_link").not(":visible")) {
				$("#step3_next_link").fadeIn(300);
			}
		}
	});
	
	$("#jq_kosarica_kontaktni_telefon_input").keyup(function() {
		if(($(this).val()).length > 0)
			$("#step3_next_link").fadeIn(300);
		else
			$("#step3_next_link").fadeOut(300);
	});
	
	/*	STEP 4 	*/
	// show step 4 next button on radio selected
	$(".radio_nacin_placila").change(function() {
		$("#input_nacin_placila").val($(this).val());
		
		if(!$("#step4_next_link").is(":visible")) {
				$("#step4_next_link").fadeIn(300);
		}
	});
	
	$("#jq_kosarica_racun_podjetje_checkbox").change(function() {
		$("#jq_kosarica_racun_podjetje_box").slideToggle();
		if($(this).is(":checked")) {
			$(this).parent().find("input[type=text]").addClass("obvezen");
		} else {
			$(this).parent().find("input[type=text]").removeClass("obvezen");
		}
	});
	
	/* SEZNAM ŽELJA */
	// add item to wish list
	$(".dodaj_izdelek_na_seznam_zelja").click(function(e) {
		e.preventDefault();
		
		var productID = $(this).attr("id");
		
		$.post(basepath + "actions/ajax.php", {action: "add_product_to_wish_list", pid: productID}, function(data) {
			var response = eval('(' + data + ')');
			
			if(response['type'] == 1) {	// user added a new product
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_product_to_wish_success",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + "<br />" +
								"Model: <strong>" + response['product_info']['product'] + "</strong><br />" +
								"Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							if(response['product_info']['inscription'] != null) {
								message_body += "Napis: <strong>" + response['product_info']['inscription'] + "</strong><br />" +
									"Velikost: <strong>" + response['product_info']['size'] + "</strong><br />";
							}
							message_body += "<br />Na seznamu želja imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";
							
							showSimpleNotification("success", notification['title'], message_body, "<a href='seznam-zelja' title='Pregled vsebine seznama želja'>V seznam želja</a>", function() {});
						}
					}
				});
			} else if(response['type'] == 2) {	// user added a product that already exists in cart
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_product_to_wish_already_in",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + "<strong>Opozorilo: </strong>" + notification['text2'] +
								"Model: <strong>" + response['product_info']['product'] + "</strong><br />" +
								"Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							if(response['product_info']['inscription'] != null) {
								message_body += "Napis: <strong>" + response['product_info']['inscription'] + "</strong><br />" +
									"Velikost: <strong>" + response['product_info']['size'] + "</strong><br />";
							}
							message_body += "<br />Na seznamu želja imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";
							
							showSimpleNotification("normal", notification['title'], message_body, "<a href='seznam-zelja' title='Pregled vsebine seznama želja'>V seznam želja</a>", function() {});
						}
					}
				});
			}
		});
		
		updateQtyString();
	});
	
	$(".odstrani_izdelek_s_seznama_zelja").click(function(e) {
		e.preventDefault();
		
		var productID = $(this).attr("id");
		var product_handle = $(this).parents(".leftbox").eq(0);
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=odstrani_izdelek_s_seznama",
			success: function(data) {
				var notification = eval('(' + data + ')');
				if(notification != false) {
					showYesNoNotification("normal", notification['title'], notification['text1'], notification['button_yes'], notification['button_no'], function() {
						$.post(basepath + "actions/ajax.php", {action: "remove_product_from_wish_list", pid: productID}, function(data) {
							if(data == "1") {
								product_handle.slideUp("fast", function() {
									product_handle.remove();
									if($(".leftbox").size() == 0) 
										location.reload();
								});
							}
						});
					}, function() {});
				}
			}
		});
		
		updateQtyString();
	});
	
	$(".odstrani_vse_izdelke_seznam_zelja").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=odstrani_vse_izdelke_s_seznama",
			success: function(data) {
				var notification = eval('(' + data + ')');
				if(notification != false) {
					showYesNoNotification("normal", notification['title'], notification['text1'], notification['button_yes'], notification['button_no'], function() {
						$.post(basepath + "actions/ajax.php", {action: "remove_all_products_from_wish_list"}, function(data) {
							if(data == "1") {
								$(".leftbox").slideUp("fast", function() {
									$(".leftbox").remove();
									location.reload();
								});
							}
						});
					}, function() {});
				}
			}
		});
		
		updateQtyString();
	});
	$(".refresh_wish_item_price").click(function(e) {
		e.preventDefault();
		
		// update all prices
		updatePrices(2, true);
	});
	$(".move_item_to_shopping_cart").click(function(e) {
		e.preventDefault();
		
		updatePrices(2, false);
		
		var productID = $(this).attr("id");
		var product_handle = $(this).parents(".leftbox").eq(0);
		
		$.post(basepath + "actions/ajax.php", {action: "add_product_to_shopping_cart", pid: productID, move_from_wish_list: 1}, function(data) {
			evaluate_actions(false);
		});
		
		$.post(basepath + "actions/ajax.php", {action: "remove_product_from_wish_list", pid: productID}, function(data) {
			if(data == "1") {
				updateQtyString();
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=move_item_to_cart",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							showSimpleNotification("success", notification['title'], notification['text1'], null, function() {
								product_handle.slideUp("fast", function() {
									product_handle.remove();
									if($(".leftbox").size() == 0) 
										location.reload();
								});
							});
						}
					}
				});
			}
		});
		
	/*	$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=evaluate_actions",
			success: function(data) {
			}
		});*/
		
		//updateQtyString();
	});
	// move all items from wish list to shopping cart
	$(".wish_list_move_all").click(function(e) {
		e.preventDefault();
		
		updatePrices(2, false);
		
		$.post(basepath + "actions/ajax.php", {action: "move_products_to_shopping_cart"}, function(data) {
			if(data == "1") {
				evaluate_actions(false);
				updateQtyString();
				
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=move_all_items_to_cart",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							showSimpleNotification("success", notification['title'], notification['text1'], null, function() {
								window.location = "kosarica/nakupovalni-vozicek";
							});
						}
					}
				});
				
				/*$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=evaluate_actions",
					success: function(data) {
					}
				});*/
			}
		});
		
		//updateQtyString();
	});
	// send wish list to a friend
	$(".wish_list_send").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: "action=check_if_user_logged_in",
			async: false,
			success: function(data) {
				response = eval('(' + data + ')');
				if(response != false) {
					
					updatePrices(2, false);
					
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=send_wish_list",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								
								message = notification['text1'];
								message += "<textarea id='notification_form_TA_emails' style='width: 99%; height: 50px;'></textarea><br /><br />" +
									notification['text2'] + "<br />" +
									"<textarea id='notification_form_TA_nagovor' style='width: 99%; height: 50px;'></textarea><br />" +
									"<input type='checkbox' value='1' id='notification_form_CB_clear' /> " + notification['text3'] + "<br /><br />";
								
								showYesNoNotification("wide", notification['title'], message, notification['button_yes'], notification['button_no'], function() {
									var emails_value = $("#notification_form_TA_emails").val();
									var nagovor_value = $("#notification_form_TA_nagovor").val();
									var clear_value = 0;
									if($("#notification_form_CB_clear").is(":checked"))
										clear_value = 1;
									
									$.ajax({
										url: basepath + "actions/ajax.php",
										type: "POST",
										async: false,
										data: "action=wish_list_send&emails=" + emails_value + "&nagovor=" + nagovor_value + "&clear=" + clear_value,
										success: function (data){
											var response1 = eval('(' + data + ')');
										
											if(response1.length > 0) {
												var emails_string = response1.join(", ");
												
												$.ajax({
													url: basepath + "actions/ajax.php",
													type: "POST",
													async: false,
													data: "action=get_notification_text&notification_identifier=send_wish_list_success",
													success: function(data) {
														var notification1 = eval('(' + data + ')');
														if(notification1 != false) {
															setTimeout( function() { showSimpleNotification("success", notification1['title'], notification1['text1'] + " <strong>" + emails_string + "</strong>.", null, function() {
																if(clear_value == 1)
																	location.reload();
															}); }, 1000);
														}
													}
												});
											} else {
												$.ajax({
													url: basepath + "actions/ajax.php",
													type: "POST",
													async: false,
													data: "action=get_notification_text&notification_identifier=send_wish_list_failed",
													success: function(data) {
														var notification1 = eval('(' + data + ')');
														if(notification1 != false) {
															setTimeout(function() { showSimpleNotification("error", notification1['title'], notification1['text1'], null, function() {}); }, 1000);
														}
													}
												});
											}
										}
									});
								});
							}
						}
					});
				} else {
					$.ajax({
						url: basepath + "actions/ajax.php",
						type: "POST",
						async: false,
						data: "action=get_notification_text&notification_identifier=send_wish_list_login_needed",
						success: function(data) {
							var notification = eval('(' + data + ')');
							if(notification != false) {
								showSimpleNotification("error", notification['title'], notification['text1'], null, function() {});
							}
						}
					});
					
				}
			}
		});
	});
	
	/* BREZPLAČNI VZORČKI */
	// add free sample to cart
	$(".dodaj_vzorcek_v_kosarico").click(function(e) {
		e.preventDefault();
		
		$.post(basepath + "actions/ajax.php", {action: "add_free_sample_to_shopping_cart"}, function(data) {
			var response = eval('(' + data + ')');
			
			// display notifications
			if(response['type'] == 1) {	// user added a new product
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_free_sample_to_cart_success",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + "" +
								"<br />Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							message_body += "<br />V nakupovalnem vozičku imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";
						
							showSimpleNotification("success", notification['title'], message_body, "<a href='kosarica/nakupovalni-vozicek' title='Pregled vsebine nakupovalnega vozička'>V nakupovalni voziček</a>", function() {});
						}
					}
				});
			} else if(response['type'] == 2) {	// user added a product that already exists in cart
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=add_free_sample_to_cart_already_in",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							message_body = notification['text1'] + notification['text2'] +
								"<br />Material: <strong>" + response['product_info']['material'] + "</strong><br />" +
								"Barva: <strong>" + response['product_info']['color'] + "</strong><br />";
							message_body += "<br />V nakupovalnem vozičku imate trenutno <strong>" + response['total_count'] + "</strong> v skupni vrednosti <strong>" + response['total_price']  + " €</strong>.<br />";

							
							showSimpleNotification("normal", notification['title'], message_body, "<a href='kosarica/nakupovalni-vozicek' title='Pregled vsebine nakupovalnega vozička'>V nakupovalni voziček</a>", function() {});
						}
					}
				});
			} else if(response['type'] == 3) {
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=free_sample_limit_reached",
					success: function(data) {
						var notification = eval('(' + data + ')');
						if(notification != false) {
							showSimpleNotification("error", notification['title'], notification['text1'], "<a href='kosarica/nakupovalni-vozicek' title='Pregled vsebine nakupovalnega vozička'>V nakupovalni voziček</a>", function() {});
						}
					}
				});
			}
		});
		
		updateQtyString();
	});
	
	/* SPLOŠNO - KOŠARICA */
	//show single answer
	$(".kosarica-faq-show-answer").click(function(e) {
		e.preventDefault();
		
		$(this).parent().next().slideToggle();
	});
	
	/* SHARE WITH FRIENDS */
	$(".share_with_friends").click(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: "action=check_if_user_logged_in",
			async: false,
			success: function(data) {
				user_info = eval('(' + data + ')');
			}
		});
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			data: "action=get_auth_question",
			async: false,
			success: function(data) {
				user_auth = eval('(' + data + ')');
			}
		});
		
		$.ajax({
			url: basepath + "actions/ajax.php",
			type: "POST",
			async: false,
			data: "action=get_notification_text&notification_identifier=share_with_friends",
			success: function(data) {
				var notification = eval('(' + data + ')');
				if(notification != false) {
					var default_body = notification['text3'].replace(/<br \/>/g, "\n");
					
					var send_form = notification['text1'] + 
						"<div style='width: 180px; line-height: 22px; float: left; clear: both;'><strong>Vaše ime: </strong></div><input type='text' id='notification_form_IN_name' size='50' value='";
					if(user_info != false)
						send_form += user_info['ime'] + " " + user_info['priimek'];
					send_form += "' /><br />" +
						"<div style='width: 180px; line-height: 22px; float: left; clear: both;'><strong>Vaš elektronski naslov: </strong></div><input type='text' id='notification_form_IN_email' size='50' value='";
					if(user_info != false)
						send_form += user_info['email'];
					send_form += "' /><br />" +
						"<div style='width: 180px; line-height: 22px; float: left; clear: both;'><strong>Naslov sporočila: </strong></div><input type='text' id='notification_form_IN_subject' size='50' value='" + notification['text2'] + "' /><br /><br />" +
						"<strong>Sporočilo:</strong><br /><textarea id='notification_form_TA_body' style='width: 99%; height: 70px;'>" + default_body + "</textarea><br /><br />" +
						"<strong>Pošlji na elektronski naslov prijatelja(-ice):</strong> (Več e-mail naslovov loči z vejico)<br /><textarea id='notification_form_TA_recipients' style='width: 99%; height: 50px;'></textarea><br /><br />" +
						"Verifikacija uporabnika: <strong>" + user_auth['question'] + "</strong><br /><input type='text' id='notification_form_IN_auth' size='50' value='' />";
					
					showYesNoNotification("wide", notification['title'], send_form, notification['button_yes'], notification['button_no'], function() {
						var auth_faqid_value = user_auth['faqid'];
						var auth_answer_value = $("#notification_form_IN_auth").val();
						$.ajax({
							url: basepath + "actions/ajax.php",
							type: "POST",
							data: "action=authenticatie_user&faqid=" + auth_faqid_value + "&answer=" + auth_answer_value,
							async: false,
							success: function(data) {
								if(data == true) {
									var name_value = $("#notification_form_IN_name").val();
									var email_value = $("#notification_form_IN_email").val();
									var subject_value = $("#notification_form_IN_subject").val();
									var body_value = $("#notification_form_TA_body").val();
									var recipients_value = $("#notification_form_TA_recipients").val();
									
									$.post(basepath + "actions/ajax.php", {action: "share_with_friends", name: name_value, email: email_value, subject: subject_value, body: body_value, recipients: recipients_value}, function(data) {
										var response = eval('(' + data + ')');
										
										if(response.length > 0) {
											var emails_string = response.join(", ");
											
											$.ajax({
												url: basepath + "actions/ajax.php",
												type: "POST",
												async: false,
												data: "action=get_notification_text&notification_identifier=share_with_friends_success",
												success: function(data) {
													var notification1 = eval('(' + data + ')');
													if(notification1 != false) {
														showSimpleNotification("success", notification1['title'], notification1['text1'] + " <strong>" + emails_string + "</strong>.", null, function() {});
													}
												}
											});
										} else {
											$.ajax({
												url: basepath + "actions/ajax.php",
												type: "POST",
												async: false,
												data: "action=get_notification_text&notification_identifier=share_with_friends_failed",
												success: function(data) {
													var notification1 = eval('(' + data + ')');
													if(notification1 != false) {
														setTimeout(function() { showSimpleNotification("error", notification1['title'], notification1['text1'], null, function() {}); }, 1000);
													}
												}
											});
										}
									});
								} else {
									setTimeout(function() { showSimpleNotification("error", "Prišlo je do napake", "Vpisali ste napačno verifikacijsko kodo.", null, function() {}); }, 1000);
								}
							}
						});
						
						
					}, function() {});
				}
			}
		});
	});
	
	/* MY PROFILE */ 
	// hover
	$(".purchase-line").hover(function() {
		$(this).css("background-color", "#ecdd3b");
	}, function() {
		$(this).css("background-color", "#FFFFFF");
	});
	
	// click
	$(".purchase-line").click(function() {
		$(this).next(".purchase-holder").slideToggle();
	});
	
	$(".mojprofil-podaki-uredi-naslov").click(function(e) {
		e.preventDefault();
		var id = $(this).attr("rel");
		if(!$(".naslov-span-" + id).is(":visible"))
		{
			$(".naslov-span-" + id).show();
			$(".naslov-input-" + id).hide();
		}
		else
		{
			$(".naslov-span-" + id).hide();
			$(".naslov-input-" + id).show();
		}
	});
	
	// zakaj? pri registraciji
	$("#jq_lastnik_jabooza_zakaj_handle").click(function() {
		showSimpleNotification("normal", "Lastnik sedežne vreče Jabooz", "<strong>Zakaj moram označiti ali sem lastnik sedežne vreče blagovne znamke Jabooz?</strong><br />Želimo vedeti koliko obstoječih lastnikov Jaboozov je odprlo svoj Udobni račun.<br />Poleg tega lastnike Jaboozov zanimajo druge stvari kot tiste, ki Jabooza (še) nimajo :)<br />Tako lahko prilagodimo besedila naših Udobnih novic, v kolikor se nanje prijavite.", null, function() {});
	});
	
	/* MAP */
	$(".show_map_notification").click(function(e) {
		e.preventDefault();
		
		showMapNotification();
	});
	
	/* BARVANJE SITTING BULL */
	if($("#barvanje").is(":visible")) {
		barvanje_interval = setInterval(function() {
			barvanje_slika++;
			if(barvanje_slika > 12) {
				barvanje_slika = 1;
				barvanje_polozaj++;
				if(barvanje_polozaj > 2)
					barvanje_polozaj = 0;
				
				$(".barvanje-polozaj").css("text-decoration", "none");
				$(".barvanje-polozaj").eq(barvanje_polozaj).css("text-decoration", "underline");
			}
			
			var polozaj_text = "sedec";
			if(barvanje_polozaj == 1)
				polozaj_text = "polsedec";
			else if(barvanje_polozaj == 2) 
				polozaj_text = "lezec";
			
			$(".barvanje-sitting-bull-active").removeClass("barvanje-sitting-bull-active").fadeOut(1000);
			$("#" + polozaj_text + "-" + barvanje_slika).addClass("barvanje-sitting-bull-active").fadeIn(1000);
		}, 5000);
	}
	
	$(".barvanje-play").click(function(e) {
		e.preventDefault();
		
		clearInterval(barvanje_interval);
		barvanje_interval = setInterval(function() {
			barvanje_slika++;
			if(barvanje_slika > 12) {
				barvanje_slika = 1;
				barvanje_polozaj++;
				if(barvanje_polozaj > 2)
					barvanje_polozaj = 0;
				
				$(".barvanje-polozaj").css("text-decoration", "none");
				$(".barvanje-polozaj").eq(barvanje_polozaj).css("text-decoration", "underline");
			}
			
			var polozaj_text = "sedec";
			if(barvanje_polozaj == 1)
				polozaj_text = "polsedec";
			else if(barvanje_polozaj == 2) 
				polozaj_text = "lezec";
			
			$(".barvanje-sitting-bull-active").removeClass("barvanje-sitting-bull-active").fadeOut(1000);
			$("#" + polozaj_text + "-" + barvanje_slika).addClass("barvanje-sitting-bull-active").fadeIn(1000);
		}, 5000);
	});
	
	$(".barvanje-pause").click(function(e) {
		e.preventDefault();
		
		clearInterval(barvanje_interval);
	});
	
	$(".barvanje-polozaj").click(function(e) {
		e.preventDefault();
		
		clearInterval(barvanje_interval);
		
		var rel = $(this).attr("rel");
		barvanje_polozaj = rel;
		
		$(".barvanje-polozaj").css("text-decoration", "none");
		$(this).css("text-decoration", "underline");
		
		var polozaj_text = "sedec";
		if(barvanje_polozaj == 1)
			polozaj_text = "polsedec";
		else if(barvanje_polozaj == 2) 
			polozaj_text = "lezec";
		
		$(".barvanje-sitting-bull-active").removeClass("barvanje-sitting-bull-active").fadeOut(100);
		$("#" + polozaj_text + "-" + barvanje_slika).addClass("barvanje-sitting-bull-active").fadeIn(1000);
	});
	
	$(".barvanje-posamezna").click(function(e) {
		e.preventDefault();
		
		clearInterval(barvanje_interval);
		
		var rel = $(this).attr("rel");
		barvanje_slika = rel;
		
		var polozaj_text = "sedec";
		if(barvanje_polozaj == 1)
			polozaj_text = "polsedec";
		else if(barvanje_polozaj == 2) 
			polozaj_text = "lezec";
		
		$(".barvanje-sitting-bull-active").removeClass("barvanje-sitting-bull-active").fadeOut(1000);
		$("#" + polozaj_text + "-" + barvanje_slika).addClass("barvanje-sitting-bull-active").fadeIn(1000);
	});
});

/*
 *		CUSTOM FUNCTIONS
 */

/**
 * 	Validates froms
 * 
 * 	@param formHandle - form DOM element
 */
function validateForm(formHandle) {
	var ok = true;
	
	formHandle.find("input.obvezen").each(function() {
		var this_ok = true;
		if($(this).attr("type") == "text" || $(this).attr("type") == "password") {
			var defValue = $(this).attr("rel");
			if(defValue === undefined)
				defValue = "";
			
			if($(this).val() == "" || $(this).val() == defValue) {
				ok = false;
				this_ok = false;
			} else if($(this).hasClass("integer")) {
				var parsed_int = parseInt($(this).val());
				if(isNaN(parsed_int)) {
					ok = false;
					this_ok = false;
					$(this).val("");
				} else {
					$(this).val(parsed_int);
				}
			}
		}
		else if($(this).attr("type") == "checkbox") {
			if(!$(this).is(":checked")) {
				ok = false;
				this_ok = false;
			}
		}
		
		var rel = $(this).attr("rel");
		if(!this_ok)
			$("[rel=" + rel + "]").slideDown();
		else
			$("label[rel=" + rel + "], span[rel=" + rel + "]").slideUp();
		
	});
	
	formHandle.find("textarea.obvezen").each(function() {
		var defValue = $(this).attr("rel");
		if(defValue === undefined)
			defValue = "";
		if($(this).val() == "" || $(this).val() == defValue)
			ok = false;
	});
	
	// checkbox groups
	formHandle.find("input[type=radio].obvezen").each(function() {
		var name = $(this).attr("name");
		var group_ok = false;
		
		$("input[name=" + name + "]").each(function() {
			if($(this).is(":checked"))
				group_ok = true;
		});
		if(!group_ok) {
			ok = false;
			
			var rel = $(this).attr("rel");
			if(!group_ok)
				$("[rel=" + rel + "]").slideDown();
			else
				$("label[rel=" + rel + "], span[rel=" + rel + "]").slideUp();
		}
	});
	
	return ok;
}

function switchImage(current_image_loc, image_count_loc) {
	var next_image = (current_image_loc + 1) % image_count_loc;
	
	//change active square
	$(".kvad-active").removeClass("kvad-active").addClass("kvad");
	$(".kvad.slika" + next_image).removeClass("kvad").addClass("kvad-active");
	
	//change acitve image
	$(".image.slika" + current_image).fadeOut(500);
	$(".image.slika" + next_image).fadeIn(500);
	
	//update current image
	current_image = next_image;
}

/**
 * 	Updates listeners on various elements
 */
function updateListeners() {
	//TSHIRT_GALLERY_RIGHT
	$(".pregled-arrow-right").unbind("click").click(function(e) {
		e.preventDefault();
		
		//if active
		if(!$(this).hasClass("inactive")) {
			current_gallery_item++;
			$(this).prev().children().eq(0).animate({left: "-" + (current_gallery_item-1)*94 + "px"}, 500);
			$(".pregled-arrow-left").removeClass("inactive");
			if(current_gallery_item+3 == gallery_item_count)
				$(this).addClass("inactive");
		}
	});	
	
	//TSHIRT_GALLERY_LEFT
	$(".pregled-arrow-left").unbind("click").click(function(e) {
		e.preventDefault();
		
		//if active
		if(!$(this).hasClass("inactive")) {
			current_gallery_item--;
			$(this).next().children().eq(0).animate({left: "-" + (current_gallery_item-1)*94 + "px"}, 500);
			$(".pregled-arrow-right").removeClass("inactive");
			if(current_gallery_item == 1)
				$(this).addClass("inactive");
		}
	});	
	
	//TSHIRT_GALLERY_SELECT
	$(".pregled-slikica").unbind("click").click(function(e) {
		e.preventDefault();
		
		//get identifier
		var classes = $(this).attr("class");
		var class_arr = classes.split(" ");
		
		//remove active class
		$("a.pregled-slikica-active").eq(0).addClass("pregled-slikica").removeClass("pregled-slikica-active");
		//add active class 
		$(this).addClass("pregled-slikica-active").removeClass("pregled-slikica");
		
		//change picture
		$(".pregled-slika-velika").hide();
		$(".pregled-slika-velika." + class_arr[0]).show();
	});
	$(".pregled-slikica-active").unbind("click").click(function(e) {
		e.preventDefault();
	});
	
	// CLICK ON NOTIFICATION CLOSE/YES/NO CLASS (notification overlay has this class also)
	$('.notification_close, .notification_yes, .notification_no').click(function() {		
		$('#notification_overlay').fadeOut(500, function() {
			$(this).remove();
		});
		$('#notification_container').fadeOut(500, function() {
			$(this).remove();
		});
		$("body").css("overflow", "visible");
	});
	
	$(".normal-l").unbind("hover").hover(function() {
		if($(this).hasClass("normal-l")) {
			$(this).css("opacity", "0.7");
			$(this).next().css("opacity", "0.7");
		}
	}, function() {
		$(this).css("opacity", "1");
		$(this).next().css("opacity", "1");
	});
	
	//change tabs
	$(".link-moj-profil-tab").click(function(e) {
		//prevent click
		e.preventDefault();
		
		//get required data
		var tabId = $(this).attr("rel");
		var ulHandle = $(this).parent().parent();
		
		//remove active-l element
		$(".active-l").remove();
		
		//change active-m and active-r to normal
		$(".active-m").removeClass("active-m").addClass("normal-l");
		$(".active-r").removeClass("active-r").addClass("normal-r");
		
		//transform clicked element into active 
		$(this).parent().before('<li class="active-l"><!-- --></li>');
		$(this).parent().removeClass("normal-l").addClass("active-m").css("opacity", "1");
		$(this).parent().next().removeClass("normal-r").addClass("active-r").css("opacity", "1");
		
		//switch content
		$("div.zavihki-textbox").hide();
		$("div." + tabId).show();
		
		//updateListeners();
	});
}

/**
 * 	updates all prices on step 1 
 */
function updatePrices(mode, refreshPage) {
	var product_ids = [];
	var product_qty = [];
	var return_value = 0;
	var refresh_page = false;
	
	$(".input-kolicina").each(function() {
		if(!isNaN(parseInt($(this).val())) && parseInt($(this).val()) > 0) {
			product_ids[product_ids.length] = $(this).attr("id");
			product_qty[product_qty.length] = $(this).val();
		}
	});
	
	$.ajax({
		url: basepath + "actions/ajax.php",
		type: "POST",
		data: ({action: "update_product_quantities", pids: product_ids, pqty: product_qty, select_array: mode}),
		async: false,
		success: function(data){
			if(data == "1") {
				return_value = 1;
				if(refreshPage)
					//location.reload();
					evaluate_actions(refreshPage);
			} else if(data == "2") {
				evaluate_actions(false);
				$.ajax({
					url: basepath + "actions/ajax.php",
					type: "POST",
					async: false,
					data: "action=get_notification_text&notification_identifier=free_sample_limit_exceeded",
					success: function(data) {
						var notification1 = eval('(' + data + ')');
						if(notification1 != false) {
							showSimpleNotification("error", notification1['title'], notification1['text1'], null, function() {
								location.reload();
							});
						}
					}
				});
			}
	    }
	});
	
	/*$.ajax({
		url: basepath + "actions/ajax.php",
		type: "POST",
		async: false,
		data: "action=evaluate_actions",
		success: function(data) {
		}
	});*/
	
	/*if(refresh_page)
		location.reload();*/
	
	return return_value;
} 

/**
 * Shows various notifications
 * 
 * @param type notification type
 * @param data data to show
 */
function showNotification(type, data, function_array) {
	// initialization
	var notification_overlay = "";
	var notification_container = "";
	var notification = "";
	var top_value = 0;
	var left_value = 0;
	var container_width = 0;
	var reload_class = "";
	
	// determine which notification to show
	switch(type) {
		case "error": 
		case "success": 
		case "normal": container_width = 640; break;
		case "wide": container_width = 950; break;
		default: container_width = 640; break;
	}
	
	// prepare notification
	notification_overlay = "<div id='notification_overlay' class='modal-overlay notification_close'></div>";
	notification_container = "<div id='notification_container' class='" + reload_class + "'></div>";
	notification = "<div class='notification-" + type + "-top'></div>";
	notification += "<div class='notification-" + type + "-middle'>" + data + "</div>";
	notification += "<div class='notification-" + type + "-bottom'></div>";
	
	// append notification html 
	$("body").append(notification_overlay);
	$("body").append(notification_container);
	$("#notification_container").css("width", container_width + "px").html(notification);
	
	// calculate position
	top_value = ($(window).height() - $("#notification_container").height()) / 2 + $(window).scrollTop();
	left_value = ( $(window).width() - container_width ) / 2 + $(window).scrollLeft();
	
	// show notification
	$('#notification_overlay').css({opacity: "0.2", top: "0px", height: $(document).height() + "px"}).fadeIn(500);
	$('#notification_container').css({top: top_value + "px", left: left_value + "px"}).fadeIn(500);
	
	// function_array
	if(function_array.length == 1) {	// normal notification
		if(typeof function_array[0] == 'function')
			$(".notification_close").unbind("click").click(function_array[0]);
	} else if(function_array.length == 2) {		// yes/no notification
		if(typeof function_array[0] == 'function')
			$(".notification_yes").unbind("click").click(function_array[0]);
		if(typeof function_array[1] == 'function')
			$(".notification_no").unbind("click").click(function_array[1]);
	}
	
	updateListeners();
}

/**
 * Shows simple notification
 * 
 * @param type
 * @param title
 * @param message
 */
function showSimpleNotification(type, title, message, left_button_title, on_close_function) {
	var button_class_l = "";
	var button_class_r = "";
	if(type != "normal") {
		button_class_l = type + "-l";
		button_class_r = type + "-r";
	}
	
	var title = "<h1 class='notification_title title_" + type + "'>" + title + "</h1>";
	var message = "<p class'notification_text'>" + message + "</p>";
	var buttons_header = "<div class='notification-buttons-header'>";
	var button = "<div class='notification-button'>" +
				"<div class='notification-button-l " + button_class_l + " notification_close'>Zapri obvestilo</div>" +
				"<div class='notification-button-r " + button_class_r + " notification_close'></div>" + 
				"</div>";
	var left_button = "";
	if(left_button_title != null) {
		left_button = "<div class='notification-button-left'>" +
			"<div class='notification-button-left-l notification_close'>" + left_button_title + "</div>" +
			"<div class='notification-button-left-r notification_close'></div>" + 
			"</div>";
	}
	var buttons_end = "<div class='clear'></div></div>";
	
	var data = title + message + buttons_header + left_button +  button + buttons_end;
	var function_array = [on_close_function];
	
	showNotification(type, data, function_array);
}

/**
 * Shows yes/no notification
 * 
 * @param type
 * @param title
 * @param message
 */
function showYesNoNotification(type, title, message, yes_title, no_title, on_yes_function, on_no_function) {
	var title = "<h1 class='notification_title title_" + type + "'>" + title + "</h1>";
	var message = "<p class'notification_text'>" + message + "</p>";
	var buttons = "<div class='yes_no_buttons'>" +
				"<div class='yes_button_l notification_yes'>" + yes_title + "</div>" +
				"<div class='yes_button_r notification_yes'></div>" + 
				"<div class='no_button_r notification_no'></div>" + 
				"<div class='no_button_l notification_no'>" + no_title + "</div>" +
				"<div class='clear'></div></div>";
	
	var data = title + message + buttons;
	var function_array = [on_yes_function, on_no_function];
	
	showNotification(type, data, function_array);
}

/**
 * Displays action response notification
 * 
 */
function displayActionNotification() {
	var notification_data = null;
	var action_notification_box = $("#actionResponseBox");
	
	if(action_notification_box.size() > 0) {
		notification_data = eval("(" + action_notification_box.html() + ")");
		// switch @resend_activation_link@ with actual link
		var message = notification_data['message'].toString();
		message = message.replace("@resend_activation_link1@", "<a href='actions/resend_activation_mail.php?uh=");
		message = message.replace("@resend_activation_link2@", "' title='Kliknite tukaj, da vam ponovno pošljemo aktivacijski email' style='color: blue;'>tukaj</a>");
		notification_data['message'] = message;
		
		showSimpleNotification(notification_data['type'], notification_data['title'], notification_data['message'], null, function() {});
	}
}

function showMapNotification() {
	var title = "<h1 class='notification_title title_wide' style='padding: 20px;'>Kako do nas?</h1>";
	var content = "<div id='right' style='float: none;'><div class='zavihki' style='width: 790px; background-image: url(img/bg-zavihki-map.png);'><ul class='zavihki-navi'>";
	content += "<li class='active-l' style='margin-left: 0px;'>" +
				"<li class='active-m'><a href='' title='Interaktivni zemljevid' class='link-moj-profil-tab' rel='tab1'>Interaktivni zemljevid</a></li>" +
				"<li class='active-r'><!--  --></li>";
	content += "<li class='normal-l'><a href='' title='Najdi.si zemljevid' class='link-moj-profil-tab' rel='tab2'>Najdi.si zemljevid</a></li>" +
				"<li class='normal-r'><!--  --></li>";
	content += "<li class='normal-l'><a href='' title='Google zemljevid' class='link-moj-profil-tab' rel='tab3'>Google zemljevid</a></li>" +
				"<li class='normal-r'><!--  --></li>";
	content += "<li class='normal-l'><a href='' title='GPS koordinate' class='link-moj-profil-tab' rel='tab4'>GPS koordinate</a></li>" +
				"<li class='normal-r'><!--  --></li>";
	content += "<li class='normal-l'><a href='' title='Natisni si' class='link-moj-profil-tab' rel='tab5'>Natisni si</a></li>" +
				"<li class='normal-r'><!--  --></li>";
	content += "</ul><div class='clear'><!--  --></div>";
	
	content += "<div class='zavihki-textbox tab1' style='width: 750px;'>" +
				"<object width='750' height='450'><param name='movie' value='img/zemljevid.swf'><embed src='img/zemljevid.swf' width='750' height='450'></embed></object>" +
				"</div>";
	content += "<div class='zavihki-textbox tab2' style='width: 750px; display: none;'><iframe src='http://zemljevid.najdi.si/maps/location/nmap.jsp?id=c864209a850741eb39c373ed79f5bc41bafd0112f08b69afec6a20e570cee43cd1f0cc24a94f5fd19300c6c679904159035ad5050f98c1e999815c3e4892b8f4' frameborder='0' width='750' height='350'></iframe></div>";
	content += "<div class='zavihki-textbox tab3' style='width: 750px; display: none;'>";
	content += '<iframe width="750" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;t=h&amp;msa=0&amp;msid=201202168059540605348.00049bf2c55adfab79abf&amp;ll=46.094365,14.449253&amp;spn=0.020832,0.064373&amp;z=14&amp;output=embed"></iframe>';
	content += "</div>";
	content += "<div class='zavihki-textbox tab4' style='width: 750px; display: none; background-color: transparent;'>" +
				"<span>Koordinate: 46.083734, 14.484961</span>" +
				"</div>";
	content += "<div class='zavihki-textbox tab5' style='width: 750px; display: none; background-color: transparent;'>" +
				"<div style='font-weight:bold;'><p onclick=\"window.open('http://www.udobje.com/navodila/IZ-SMERI-LJUBLJANA-CENTER.html', 'IZ SMERI LJUBLJANA CENTER', 'width=490, height=700'); return false;\" style='cursor:pointer;'>&rarr; IZ SMERI LJUBLJANA CENTER</p><br /><p onclick=\"window.open('http://www.udobje.com/navodila/PO-LJUBLJANSKI-OBVOZNICI-IZ-SMERI-VIC.html', 'PO LJUBLJANSKI OBVOZNICI IZ SMERI VIČ', 'width=490, height=700'); return false;\" style='cursor:pointer;'>&rarr; PO LJUBLJANSKI OBVOZNICI IZ SMERI VIČ</p><br /><p onclick=\"window.open('http://www.udobje.com/navodila/IZ-SMERI-GORENJSKA-KRANJ.html', 'IZ SMERI GORENJSKA [KRANJ]', 'width=490, height=700'); return false;\" style='cursor:pointer;'>&rarr; IZ SMERI GORENJSKA [KRANJ]</p><br /><p onclick=\"window.open('http://www.udobje.com/navodila/PO-LJUBLJANSKI-OBVOZNICI-IZ-SMERI-BEZIGRAD.html', 'PO LJUBLJANSKI OBVOZNICI IZ SMERI BEŽIGRAD', 'width=490, height=700'); return false;\" style='cursor:pointer;'>&rarr; PO LJUBLJANSKI OBVOZNICI IZ SMERI BEŽIGRAD</p></div>" +
				"</div>";
	content += "<div class='clear'></div></div></div>";
	
	var button = "<div class='notification-button'>" +
	"<div class='notification-button-l notification_close'>Zapri zemljevid</div>" +
	"<div class='notification-button-r notification_close'></div>" + 
	"</div><div class='clear'></div>";
	
	data = title + content + button;
	
	showNotification("wide", data, function() {});
}

/**
 * Initializes page
 */
function pageInitialization() {
	// set width for product tabs
	var occupied_width = 0;
	var tab_count = 0;
	var tab_padding = 10;	// current padding
	var padding_left = 0;	// additional left padding
	var padding_right = 0;	// additional right padding
	var new_padding = 0;
	$(".link-izdelek-tab").each(function() {
		var parent = $(this).parent();
		if(parent.hasClass("active-m")) {
			occupied_width += parent.prev().width();
		}
		occupied_width += parent.width();
		occupied_width += parent.next().width();
		tab_count++;
	});
	occupied_width += tab_count; // each tab has 1px left-margin
	occupied_width += (tab_count-1) * tab_padding; // tab_count-1 tabs are not active and have 10px padding
	var extra_width = 720 - occupied_width;
	if(tab_count > 0 && extra_width > 0) {
		var extra_tab_width = Math.floor(extra_width / tab_count);
		var width_leftover = extra_width - (extra_tab_width * tab_count);
		
		new_padding = Math.floor(extra_tab_width / 2);
		if(extra_tab_width % 2 == 0) {	// even extra width
			padding_left = new_padding;
			padding_right = new_padding;
		} else {
			padding_left = new_padding;
			padding_right = new_padding + 1;
		}
		
		$(".active-m").css("padding-left", padding_left + "px").css("padding-right", padding_right + "px");
		$(".normal-l").css("padding-left", (padding_left + 10) + "px").css("padding-right", padding_right + "px");
		$(".link-izdelek-tab").eq(tab_count-1).parent().css("padding-right", (padding_right + width_leftover - 1) + "px");
	}
	
	// position product title image
	$("#izdelek_title_image_img").load(function() {
		image_height = $("#izdelek_title_image_img").height();
		
		var add_margin = 0;
		if(image_height > 0)
			add_margin = 100 - image_height;
		margin = 19 + add_margin;
		$("#izdelek_title_image").css("margin-top", margin + "px");
	});
}
$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

// update qty string
function updateQtyString() {
	$.ajax({
		url: basepath + "actions/ajax.php",
		type: "POST",
		async: false,
		data: "action=update_qty_string",
		success: function(data) {
			data_array = data.split("@");
			$("#jq_wish_list_qty_string").html(" [" + data_array[0] + "]");
			$("#jq_cart_qty_string").html(" [" + data_array[1] + "]");
		}
	});
}

// evaluate actions 
function evaluate_actions(reloadPage) {
	$.ajax({
		url: basepath + "actions/ajax.php",
		type: "POST",
		async: false,
		data: "action=evaluate_actions",
		success: function(data) {
			if(reloadPage)
				location.reload();
		}
	});
}

/*	PAUSABLE INTERVAL CLASS */

function Interval(code, miliseconds) {
	var id = this;
	var interval_handle = null;
	var interval = miliseconds;
	var interval_start = new Date();
	var remaining_time = miliseconds;
	var paused = false;
	var code = code;
	
	this.reset_time = function() {
		interval_start = new Date();
		remaining_time = interval;
		id.resume();
	};
	
	this.resume = function() {
		interval_handle = setTimeout(function() { code.call(); id.reset_time();}, remaining_time);
		interval_start = new Date();
	};
	
	this.pause = function() {
		clearTimeout(interval_handle);
		remaining_time = interval - (new Date() - interval_start);
	};
	
	this.resume();
}
