$(document).ready(function() {
;(function($){
var base = this;
/**---------------------------
Solo productlist url cookies v0.1
----------------------------**/
function getCookie(c_name) {
	var i, x, y, ARRcookies = document.cookie.split(";");
	for (i = 0; i < ARRcookies.length; i++) {
		x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
		x = x.replace(/^\s+|\s+$/g, "");
		if (x == c_name) {
			return unescape(y);
		}
	}
}

/*
function setCookie(c_name, value, exdays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	document.cookie = c_name + "=" + c_value;
}
*/

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function checkCookie() {
	//set back to previous page in case of cookies bering off
	//buttonEvent(document.referrer);
	//url validation
	var currentUrl = location.href;
	if (currentUrl.indexOf('/pl/') != -1) {
		setCookie("pageUrl", currentUrl, 365);
	}
	else {
		var pageUrl = getCookie("pageUrl");
		if (pageUrl != null && pageUrl != "") {
			//alert("The stored url is: " + pageUrl);
			buttonEvent(pageUrl);
		} 
	}
}

function buttonEvent(link) {
	$('.link_listpage').attr('href',link);
}
/**---------------------------
INITIATE FUNCTIONS AND LISTENERS
----------------------------**/
	checkCookie();
	

/** CHANGE LOG 
v0.1
- PROTOTYPE

----------------------------**/
})(jQuery);
});
