var dt,nxtprv,d,f,time,time2,time3,nxtc,prvc,autotimer,_OnOff="off",Auto_timerI,rdycls="";
var globalPg_Width=1000;
var Global_Autotime=3000;
var If_lisT=30;
function FGImage(){
var args=arguments;
var bsg=document.getElementsByTagName("body")[0];
var c1=document.createElement("div");
var v1=document.createElement("div");
var v2=document.createElement("div");
var c1s=$("mainbody");
var v1s=$("imgby");
var v2s=$("imgtb");
if(c1s && v1s && v2s){
}else{
c1.setAttribute("id","mainbody");
bsg.appendChild(c1);
v1.setAttribute("id","imgby");
c1.appendChild(v1);
v2.setAttribute("id","imgtb");
c1.appendChild(v2);
bsg.insertBefore(c1,bsg.firstChild);
mainfd("start");

}
v1.style.height=getDocHeight()+"px";
$("mainbody").style.width="100%";
$("imgtb").style.margin="0 auto";
$("imgtb").style.width="100%";
//alert($("mainbody").style.width+' '+$("mainbody").style.height);
if(_OnOff=="off"){_AutoOff(args[0],args[1],args[2]);}else if(_OnOff=="on"){_AutoOn(args[0],args[1],args[2]);}
window.onresize=function(){resizex()};
window.onscroll=function(){$("imgtb").style.top=parseInt(posTop()+20)+"px";};
return false;
}
function mainfd(prt){
var speed3=Math.round(400 / 100);
var timer3=30,i,a,b;
if(prt=="start"){
for(i=1;i<=80;i++){
time3 = setTimeout("mainfdp('"+i+"')",(timer3 * speed3));
timer3++;
}
}else if(prt=="end"){
for(i=80;i>=-1;i--){
time3 = setTimeout("mainfdp('"+i+"')",(timer3 * speed3));
timer3++;
}
}
}
function mainfdp(opc){
var tc=$("imgby");
tc.style.visibility="visible";
tc.style.opacity = (opc / 100);
tc.style.MozOpacity = (opc / 100);
tc.style.KhtmlOpacity = (opc / 100);
tc.style.filter = "alpha(opacity=" + opc + ")";
if(opc==80){clearTimeout(time3);}else if(opc==0){rdycls="done";clearTimeout(time3);remoth();}
}
function $(x){return document.getElementById(x);}
/***************************************
page setting
***************************************/
function resizex(){var v1s=$("imgby");v1s.style.width=eleHW("body").w+"px";v1s.style.width=eleHW("body").w+"px";}
function pageWidth() {return window.innerWidth!=null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body!=null? document.body.clientWidth:null;} 
function pageHeight() {return window.innerHeight!=null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body!=null? document.body.clientHeight:null;} 
function posLeft() {return typeof window.pageXOffset!='undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;} 
function posTop() {return typeof window.pageYOffset!='undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
function ineleftfix(x){if(x==null){x=300;}var imdivb=$("imgtb");imdivb.style.left=parseInt(pageWidth())/2-(x/2)+"px";imdivb.style.top = parseInt(posTop() + 25) +"px";}
function eleHW(c){var po = $(c);var otp = new Object();var _eleheight = _eleheight !== undefined ? po.height : po.style.height ? po.style.height: po.offsetHeight ? po.offsetHeight : _eleheight;var _elewidth = _elewidth !== undefined ? po.width : po.style.width ? po.style.width: po.offsetWidth ? po.offsetWidth : _elewidth;otp.h = _eleheight;otp.w = _elewidth;return(otp);}
/***************************************
Normal display
***************************************/
function _AutoOff(){
var args=arguments;
_OnOff="off";
_IMGplay(args[0],args[1],args[2]);
}
function _AutoOn(){
var args=arguments;
_OnOff="on";
_IMGplay(args[0],args[1],args[2]);
}
function _IMGplay(){
clearTimeout(Auto_timerI);
var args=arguments,autoplayno;
ineleftfix("430");
resizex();
//fscroll();
var v1s=$("imgby"),v2s=$("imgtb"),c1=$("mainbody"),aup,Aname=$("A"+args[0]).name;
var prevbt = parseInt(args[0]) - 1;
var nxbt = parseInt(args[0]) + 1;
nxtprv="";
nxtprv = '<table border="0" cellpadding="0" cellspacing="0" id="btmstb"><tr><td width="12"></td><td align="left"><span class="nonwd">Image&nbsp;'+args[0]+'&nbsp;of&nbsp;'+args[1]+'</span>&nbsp;&nbsp;';
if(args[0]>1){
var dt = $("A"+prevbt);
var onclickp = dt.getAttributeNode('onclick').nodeValue;
nxtprv += '<a id="prev" href="'+dt.href+'" onclick="'+onclickp+'" class="buttonwd">Prev</a>';
prvc = 'onmouseover=\'shtxt("Leftbt")\' onmouseout="remv(\'Leftbt\')" onclick="'+onclickp+'"';
}else{
prvc='';
nxtprv += '<span class="nonwd">Prev</span>';
}
nxtprv += '<span class="nonwd">&nbsp;&hArr;&nbsp;</span>';
if(nxbt<=args[1]){
var vt = $("A"+nxbt);
var onclickn = vt.getAttributeNode('onclick').nodeValue;
nxtprv += '<a id="next" href="'+vt.href+'" onclick="'+onclickn+'" class="buttonwd">Next</a>';
nxtc = 'onmouseover=\'shtxt("Rightbt")\' onmouseout="remv(\'Rightbt\')" onclick="'+onclickn+'"';
autoplayno = nxbt;
}else{
nxtprv += '<span class="nonwd">Next</span>';
nxtc='';
autoplayno = "1";
}
if(Aname=="ImL"){
if(_OnOff=="on"){
aup = '<a href="javascript:_AutoStop(\''+autoplayno+'\',\''+args[1]+'\',\''+args[2]+'\')" id="autoplay" class="buttonwd">Stop</a>';
}else if(_OnOff=="off"){
aup = '<a href="javascript:_AutoOn(\''+autoplayno+'\',\''+args[1]+'\',\''+args[2]+'\')" id="autoplay" class="buttonwd">Play</a>';
}
}else{
if(_OnOff=="on"){
aup = '<a href="javascript:_AutoStop(\''+autoplayno+'\',\''+args[1]+'\')" id="autoplay" class="buttonwd">Stop</a>';
}else if(_OnOff=="off"){
aup = '<a href="javascript:_AutoOn(\''+autoplayno+'\',\''+args[1]+'\')" id="autoplay" class="buttonwd">Play</a>';
}
}
nxtprv += '</td><td align="right">'+aup+'&nbsp;&nbsp;<a href="javascript:" onclick="remchl()" class="buttonwd">Close</a></td></tr></table>';
var titlename;
if($("B"+args[0])){titlename = ""/*$("B"+args[0]).name*/;}else{titlename="";}
v2s.innerHTML = '<table id="P1" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"><tr><td colspan="4" bgcolor="#FFCC99"><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="4" height="5"></td></tr><tr><td width="10"></td><td id="P2" height="20"><span class="imgtitle">'+titlename+'</span></td><td align="right" width="10"><a href="javascript:" onclick="remchl()" class="button">X</span></td><td width="10"></td></tr><tr><td colspan="4" height="5"></td></tr></table></td></tr><tr><td colspan="4" height="10"></td></tr><tr><td rowspan="3" width="10"></td><td id="blt" align="center" valign="middle" style="background:url(templates/'+tojavascript+'/images/loading.gif) center no-repeat;background-color:#333333;"><div id="pgk" style="background-repeat:no-repeat;"></div></td><td rowspan="3" width="10"></td></tr><tr><td height="10"></td></tr></table><div style="overflow:hidden; position:absolute;"><table border="0" cellpadding="0" cellspacing="0" id="imgbtn" style="position:relative"><tr><td id="btmbar">'+nxtprv+'</td></tr></table></div>';
$("P2").width="320";$("P1").width="350";$("blt").width="330";$("pgk").style.height="330px";$("btmstb").width="330";
$("pgk").style.background = "";
$("pgk").style.visibility = "hidden";
var v3s = $("imgbtn");
v3s.style.top = "100px";
loadimg(args[0],args[1],args[2],autoplayno);
if(Aname=="ImL"){
var cpg=Math.ceil(args[0]/If_lisT);
shwhid(cpg,args[2]);
}
resizex();
//fscroll();
}
/***************************************
Auto stop
***************************************/
function _AutoStop(){
_OnOff="off";
var args=arguments,Aname=$("A"+args[0]).name;
clearTimeout(Auto_timerI);
$("ontopbt").style.visibility="visible";
$("autoplay").innerHTML="Play";
if(Aname=="ImL"){
//$("autoplay").attributes["onclick"].value='_AutoOn(\''+args[0]+'\',\''+args[1]+'\',\''+args[2]+'\')';
//$("autoplay").setAttribute('onclick','_AutoOn(\''+args[0]+'\',\''+args[1]+'\',\''+args[2]+'\')');
$("autoplay").href='javascript:_AutoOn(\''+args[0]+'\',\''+args[1]+'\',\''+args[2]+'\')';
}else{
//$("autoplay").attributes["onclick"].value='_AutoOn(\''+args[0]+'\',\''+args[1]+'\')';
//$("autoplay").setAttribute('onclick','_AutoOn(\''+args[0]+'\',\''+args[1]+'\')');
$("autoplay").href='javascript:_AutoOn(\''+args[0]+'\',\''+args[1]+'\')';
}
}
/***************************************
Remove all element
***************************************/
function remoth(){
var bsg = document.getElementsByTagName("body")[0];
var y = $("mainbody");
var x = $("imgby");
y.removeChild(x);
bsg.removeChild(y);
}
function remchl(){
_OnOff="off";
clearTimeout(Auto_timerI);
var bsg = document.getElementsByTagName("body")[0];
var y = $("mainbody");
var w = $("imgtb");
y.removeChild(w);
mainfd("end");
window.onscroll = function(){};
window.onresize = function(){};
}
/***************************************
Loading image add bottom button
***************************************/
function loadimg(){
var args=arguments,Aname=$("A"+args[0]).name;
var imgnow = $("A"+args[0]);
var vk2 = new Image();
var gh = $("pgk");
vk2.src = imgnow.href;
var ck = $("blt");
if(vk2.complete){
var ghw=vk2.width,ghg=vk2.height;
if(ghw<350&&ghg<350){ghw=350;ghg=350;}else if(ghw<350){ghw=350;}
gh.style.background="url("+vk2.src+")"; 
gh.style.backgroundRepeat="no-repeat";
gh.style.backgroundPosition="center";
shimgslt();
shelem();
var tc=parseInt(ghg)+10;
var tbW = parseInt(ghw)-20;
var ttW = parseInt(ghw) + 20;
var half=ghw/2;
$("P2").width=tbW;$("P1").width=ttW;ck.width=ghw;$("pgk").style.height=ghg+"px";$("btmstb").width=ghw;
ineleftfix(gh.width,gh.height);
ck.style.background="";
ck.style.backgroundColor="#333333";
$("pgk").innerHTML += '<table id="ontopbt" border="0" cellpadding="0" cellspacing="0" width="'+ghw+'" style="height:'+ghg+'px;" id="pnbut"><tr><td width="'+half+'" height="'+ghg+'" '+prvc+' id="Leftbt" align="left" valign="top"></td><td width="'+half+'" height="'+ghg+'" '+nxtc+' id="Rightbt" align="right" valign="top"></td></tr></table>';
if(_OnOff=="off"){
$("ontopbt").style.visibility="visible";
}else if(_OnOff=="on"){
$("ontopbt").style.visibility="hidden";
if(Aname=="ImL"){
Auto_timerI=setTimeout("_AutoOn('"+args[3]+"',\'"+args[1]+"\',\'"+args[2]+"\')",Global_Autotime);
}else{
Auto_timerI=setTimeout("_AutoOn('"+args[3]+"',\'"+args[1]+"\')",Global_Autotime);
}
}
ineleftfix(ghw);
vk2.onload=function(){};
}else{
vk2.onload = function() {
if(args[3]!=null){
loadimg(args[0],args[1],args[2],args[3]);
}else{
loadimg(args[0],args[1],args[2]);
}
}}}
/***************************************
Image opacity & below image button
***************************************/
function shelem(){
var speed2=Math.round(400 / 100);
var timer2=30;
var tc=$("imgbtn");
tc.style.display="block";
for(i=-100;i<=0;i++){
time2 = setTimeout("setelem('"+i+"')",(timer2 * speed2));
timer2++;
}
}
function setelem(ht){
var tc=$("imgbtn");
tc.style.top = ht+"px";
if(ht==0){clearTimeout(time2);}
}
function shimgslt(){
var speed = Math.round(400 / 100);
var timer = 30;
for(i=0;i<=100;i++){
time = setTimeout("setalpha('"+i+"')",(timer * speed));
timer++;
}
}
function setalpha(opc){
c = $("pgk");
c.style.visibility = "visible";
c.style.opacity = (opc / 100);
c.style.MozOpacity = (opc / 100);
c.style.KhtmlOpacity = (opc / 100);
c.style.filter = "alpha(opacity=" + opc + ")";
if(opc == 100){clearTimeout(time);}
}
/***************************************
On top image button
***************************************/
function shtxt(xx){
var vv;
var showtxt;
var tt = $(xx);
tt.style.cursor = "pointer";
if(xx == "Leftbt"){
showtxt = "&nbsp;&nbsp;&nbsp;Prev";
}else if(xx == "Rightbt"){
showtxt = "Next&nbsp;&nbsp;&nbsp;";
}
vv = tt.getAttributeNode('onclick').nodeValue;
tt.innerHTML = '<a href="javascript:" onclick="'+vv+'" class="showtxt">'+showtxt+'</a>';
}
function remv(xx){
var tvt = $(xx);
tvt.innerHTML = "";
}
/***************************************
Display page number n control page show hide
***************************************/
function shwhid(x,vh){
var cp=0,i,th,vth,gp = '';
var xz=document.getElementById("Tb"+x);
for(i=1;i<=vh;i++){
cp++;
vth=parseInt(x)-1;
var page_going_show=document.getElementById("Tb"+i);
if(i==1&&page_going_show!=xz){gp+='<a href="javascript:" onclick="shwhid(\''+vth+'\',\''+vh+'\');" class="pglnk"><<&nbsp;Prev&nbsp;&nbsp;</a>&nbsp;&nbsp;';}
if(page_going_show == xz){
//t.style.display = 'block';
page_going_show.className="on";
if(vh != 1){gp += '<span class="pglnkhg">'+i+'</span>';}
}else{
//t.style.display = 'none';
page_going_show.className="off";
gp += '<a href="javascript:" onclick="shwhid(\''+i+'\',\''+vh+'\');" class="pglnk">'+i+'</a>';
}
th = parseInt(x)+1;
if(x < i && cp == vh){gp += '&nbsp;&nbsp;<a href="javascript:" onclick="shwhid(\''+th+'\',\''+vh+'\');" class="pglnk">&nbsp;&nbsp;Next&nbsp;>></a>';}
}
$("numbar").innerHTML = gp;
}

