document.write('<style>.ab-thumbs-cont{display:none!important;}</style>');

function $(id){
	return document.getElementById(id);
}

oGalData=new Array();

var oTotalItem;
var selThumb;
var oThumbWidth=93;
var oThumbDisplay=3;

function popThumbs(){
	oLists=$('ab-gal-img').getElementsByTagName('li');
	oTotalItem=oLists.length;
	for(i=0;i<oLists.length;i++){
		oAnchor=oLists[i].getElementsByTagName('a')[0];
		oGalleryLink=oAnchor.href;
		oGalleryThumb=oAnchor.getElementsByTagName('img')[0].src;
		oGalleryTitle=oAnchor.lastChild.data;
		oGalPush='<div class="ab-thumbs" id="ab-thumbs-'+i+'"><a target="_blank" href="'+oGalleryLink+'" title="'+oGalleryTitle+'"><img src="'+oGalleryThumb+'" alt="'+oGalleryTitle+'" /></a></div>';
		oGalData.push(oGalPush);
		if(i==20){i=oLists.length};
	}
	$('ab-gal-img').innerHTML="";
	$('ab-gal-img').innerHTML='<div class="ab-thumbs-scroller" id="ab-thumbs-scroller" style="width:'+((oTotalItem*oThumbWidth)/2)+'px;margin-left:0px;">'+oGalData.join('')+'</div>';
	$('ab-title').innerHTML;

	changeTitle($('ab-thumbs-0').getElementsByTagName('a')[0].href,$('ab-thumbs-0').getElementsByTagName('a')[0].title);
	assignClass('add',$('ab-thumbs-0').getElementsByTagName('a')[0],'thumb-sel');
	selThumb='ab-thumbs-0';
}





function showTitle(evt){

	if(evt.target){
		oElm=evt.target;
	}else if(evt.srcElement){
		oElm=evt.srcElement;
	}

	if(oElm.nodeName=="IMG"){
		//IF Starts
		if(oElm.parentNode.parentNode.className=="ab-thumbs"){
			changeTitle(oElm.parentNode.href,oElm.parentNode.title);
			assignClass('remove',$(selThumb).getElementsByTagName('a')[0]);
			assignClass('add',oElm.parentNode,'thumb-sel');
			selThumb=oElm.parentNode.parentNode.id;
		}
		//IF Ends
	}else if(oElm.parentNode.className=="ab-gal-btn-left"){
		oElm.onclick=function(){
			scrollThumbs('left');
		}
	}else if(oElm.parentNode.className=="ab-gal-btn-right"){
		oElm.onclick=function(){
			scrollThumbs('right');
		}
	}
}

function assignClass(oType,oElement,oClass){
	if(oType=='add'){
		oElement.className=oClass;
	}else if(oType=='append'){
		oElement.className+=oClass;
	}else{
		oElement.className="";
	}

}

function changeTitle(oUrl,oTitle){
	$('ab-title').innerHTML='<a href="'+oUrl+'" target="_blank" title="View '+oTitle+' Gallery">'+oTitle+'</a>';
}

function scrollThumbs(dir){
	oScroller=$('ab-thumbs-scroller');
	oMaxScroll=(oTotalItem*oThumbWidth)/2;
	oScrollMargin=oThumbWidth*oThumbDisplay;
	oCurMargin=oScroller.style.marginLeft;
	oCurMargin=oCurMargin.split('px');
	oCurMargin=oCurMargin[0];
	oRemaining=-(oCurMargin/oThumbWidth);


	if(dir=="left"){
		if(oCurMargin >= 0){
			if(oMaxScroll-oScrollMargin<oScrollMargin){
				oDestMargin=-(oScrollMargin);
				oDir="decrement";
			}else{
				oDestMargin=-(oMaxScroll-oScrollMargin);
				oDir="decrement";
			}
		}else if(oRemaining<oThumbDisplay){
			oDestMargin=0;
			oDir="increment"
		}else{
			oDestMargin=eval(oCurMargin+'+'+oScrollMargin);
			oDir="increment";
		}

	}else if(dir=="right"){
		if(oCurMargin <= -(oMaxScroll-oScrollMargin)){
			oDestMargin=0;
			oDir="increment";
		}else{
			oDestMargin=eval(oCurMargin+'-'+oScrollMargin);
			oDir="decrement";
		}

	}
	oScroller.style.marginLeft=oDestMargin+"px";

	//change selection and titles

	assignClass('remove',$(selThumb).getElementsByTagName('a')[0]);
	selThumb="ab-thumbs-"+Math.abs(oDestMargin/oThumbWidth);
	assignClass('add',$(selThumb).getElementsByTagName('a')[0],'thumb-sel');
	changeTitle($(selThumb).getElementsByTagName('a')[0].href,$(selThumb).getElementsByTagName('a')[0].title);

}