function getCookie (name){

	var arg = name + "=";
	var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen){

		var j = i + alen;

        if (document.cookie.substring(i, j) == arg){
			var tmp = getCookieVal(j);
			setCookie(name, "");
			return tmp;
		}

        i = document.cookie.indexOf(" ", i) + 1;

        if (i == 0){
			break;
		}
	}

	return "";
	
}

function getCookieVal (offset){

	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1){
		endstr = document.cookie.length;
	}

	return unescape(document.cookie.substring(offset, endstr));

}

function get_country() {

	var country = getCookie("ii_country_selected");

	setCookie("ii_country_selected", "");

	return country;

}

function setCookie (name, value){

	var cookieExpDate = new Date ();	

	cookieExpDate.setTime(cookieExpDate.getTime() + (365 * 24 * 3600 * 1000));

    document.cookie = name + "=" + escape (value) +

		"; expires=" + cookieExpDate.toGMTString() +

		"; path=/" +

        "; domain=.classmatepc.com" 
}

function parsePathName(url){		

	var pathObject = new Object();

	pathObject.dir = new Array();

	i = 0;

	pathObject.fullDir = "";

	strURL = url.replace(/^\//,"");

	while ((node = strURL.match(/^(.+?)(?:\/)+(.*)/)) && node[0].length){

		pathObject.dir[i++] = node[1]; 					

		pathObject.fullDir += node[1] + "/";

		strURL = node[2];

	}

	pathObject.fileName = strURL;

	return pathObject;

}


jQuery(document).ready(function($) {	

	var path = parsePathName(location.pathname.toLowerCase());	
	var storePath = path.fullDir.replace(/\//g,'+');

	//$('#showVal').text(getCookie('iid_container'));
	
	jQuery('a').click(function(){
		var clicked = $(this);
		var iidVal = clicked.attr('iid');
				
		if(!iidVal){
			setCookie('iid_container',"");
		}
		else{
			setCookie('iid_container',storePath.toString() + iidVal.toString());			
		}
	});
	
})
