//get cookie
function getCookie(c_name)
{
if (document.cookie.length>0)
{ 
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{ 
c_start=c_start + c_name.length+1 
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
} 
}
return ""
}
 
 
//set cookie
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}
 
 
 
//call this function from your image load function or add it to it
function getglgScrollerPosition()
{
glgscrollerposition=getCookie('glgscrollerposition')
if (glgscrollerposition!=null && glgscrollerposition!="")
  { 
  	//alert("found cookie");
  	//alert(glgscrollerposition);
  	return parseInt(glgscrollerposition);
   }
else 
  { 
  
  	return 0;
  }
}
 
 
 
// use this code to set your cookie when some one clicks on a button
function setglgScrollerPosition() {
		//	alert("in setglgScrollerPosition: tOffset=" + tOffset); 
			glgscrollerposition=tOffset;
            setCookie('glgscrollerposition',glgscrollerposition,365)
}
// function initgallery() {
// 	$('a').each(function() {
// 		if (this.getAttribute('href') && (this.getAttribute('rel') == 'slide')){
// 			this.onclick = function () {
// 				$("#slide").toggle();
// 				$("#slideimg").html('<img src="'+this.href+'" width="450" height="450" alt="'+this.getAttribute("title")+'" title="'+this.getAttribute("title")+'" />');
// 				$("#slidecaption").html("<em>"+this.getAttribute("title")+"</em>");
// 				setTimeout("$('#slide').show('slow')", 2000);
// 				return false;
// 			}
// 		}
// 	});
// 	
// 	var allThumbs = $("#thumbs a").get();
// 	thumbLength = allThumbs.length;
// 	tOffset = getglgScrollerPosition();
// 	alert("tOffset=" + tOffset);
// 	document.getElementById("thumbs").style.marginLeft = tOffset + "px";
// }

function initgallery(offset) {
    //debugger;
	$('a').each(function() {
		if (this.getAttribute('href') && (this.getAttribute('rel') == 'slide')){
			this.onclick = function () {
				$("#slide").toggle();
				$("#slideimg").html('<img src="'+this.href+'" width="450" height="450" alt="'+this.getAttribute("title")+'" title="'+this.getAttribute("title")+'" />');
				$("#slidecaption").html("<em>"+this.getAttribute("title")+"</em>");
				setTimeout("$('#slide').show('slow')", 2000);
				return false;
			}
		}
	});
	
	var allThumbs = $("#thumbs div.phoneblock").get();
	thumbLength = allThumbs.length;
	tOffset = 0;
	tOffset = offset;
	setglgScrollerPosition();
	document.getElementById("thumbs").style.marginLeft = tOffset + "px";
}

function leftScroll() {
	doscroll=0;
	if(tOffset < 0) {
		tOffset = tOffset + 10;
		document.getElementById("thumbs").style.marginLeft = tOffset + "px";
		doscroll = setTimeout("leftScroll()", 30);
	}
	//else{
	//	doscroll=0;
	//}


	if (tOffset >= 0) {
	    document.getElementById("linkLeftPhone").style.visibility = "hidden";
	}

	document.getElementById("linkRightPhone").style.visibility = "visible";
}

function rightScrollInit() {
	if(tOffset > ((thumbLength * thumbWidth) - ((thumbLength * thumbWidth) * 2) - 10) + scrollDivWidth + 10) {
		tOffset = tOffset - 10;
		document.getElementById("thumbs").style.marginLeft = tOffset + "px";
		doscroll = setTimeout("rightScroll()", 5);
	}
	else{
		doscroll=0;
	}
}

function rightScroll() {
    //debugger;
    //alert(tOffset);
	if(tOffset > ((thumbLength * thumbWidth) - ((thumbLength * thumbWidth) * 2) - 10) + scrollDivWidth + 10) {
		tOffset = tOffset - 10;
		document.getElementById("thumbs").style.marginLeft = tOffset + "px";
		doscroll = setTimeout("rightScroll()", 30);
	}
	else {
	    //debugger
		doscroll=0;
    }

    if (tOffset <= ((thumbLength * thumbWidth) - ((thumbLength * thumbWidth) * 2) - 10) + scrollDivWidth + 10) {
        document.getElementById("linkRightPhone").style.visibility = "hidden";
    }

	document.getElementById("linkLeftPhone").style.visibility = "visible";
}

function stopScroll() {
	if(doscroll) clearTimeout(doscroll);
}

 

	
	 
	