var g = new Array();

//layer hiddener
function shSec(id)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	if(o)
	{
		if(o.style.display=="block")
			o.style.display="none";
		else
			o.style.display="block";
	}
}

//show a layer
function hideL(id)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	o.style.display="none";
}

//hide a layer
function showL(id)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	o.style.display="block";
}

//popup opener
function go(wintype,w,h,command)
{
  st=new String("toolbar=no,directories=no,status=no,scrollbars=no,menubar=no,width="+w+",height="+h);
  picture=window.open(wintype+command,"picture",st);
  picture.window.focus();
}

//layer hiddener with iconchanger
function FShow(id,icono,iconc)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	var i=document.getElementById('b'+id);
	if(o)
	{
		if(o.style.display=="block")
		{
			o.style.display="none";
			i.src=iconc;
		}
		else
	 {
			o.style.display="block";
			i.src=icono;
	 }
	}
}

//make an imput empty
function emptyInput(id)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	o.value="";
}

//fill an imput field
function fillInput(id,val)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	if(o.value=='') o.value=val;
}

// Leap year detector for date scripts
function exxiteLeapYear(year)
{
	if(year%4 == 0)
	{
		if(year%100 != 0)
		{
			return(true);
		}
		else
		{
			if(year%400 == 0){return(true);}else{return(false);}
		}
	}
  return(false);
}


function exxiteDateToUnixtime(oyear,omonth,oday,ohour,ominute)
{
		var humDate = new Date(Date.UTC(oyear,(omonth-1),oday,ohour,ominute,0));
		return(humDate.getTime()/1000.0);
}

//Date control javascript----------------------------
function exxiteDateControl(mid,control,yeard)
{
	if(!document.getElementById) return;
	oyear=document.getElementById(mid+'_year');
	omonth=document.getElementById(mid+'_month');
	oday=document.getElementById(mid+'_day');
	ohour=document.getElementById(mid+'_hour');
	ominute=document.getElementById(mid+'_minute');
	ostamp=document.getElementById(mid+'_stamp');
	myear=parseInt(oyear.value);
	mmonth=parseInt(omonth.value);
	mday=parseInt(oday.value);
	mhour=parseInt(ohour.value);
	mminute=parseInt(ominute.value);
	leap=exxiteLeapYear(myear);
	if(control=='y')
	{
		oyear.options.length=0;
		for(i=(-1*(yeard)); i<=yeard; i++)
		{
			  oyear.options[i+yeard]=new Option(myear+i,myear+i);
		}
		oyear.selectedIndex=yeard;
	}
	if(control=='m' || (control=='y'))
	{
		if((mmonth==4) || (mmonth==6) || (mmonth==9) || (mmonth==11)) max=30;
	  if((mmonth==1) || (mmonth==3) || (mmonth==5) || (mmonth==7)  || (mmonth==8) || (mmonth==10)  || (mmonth==12)) max=31;
	  if(mmonth==2)
	  {
	  	max=28;
	  	if(leap) max=29;
	  }
	  oday.options.length=0;
	  for(i=0; i < max; i++)
		{
      	oday.options[i]=new Option(String(i+1),String(i+1));
		}
		if(mday>max) mday=2;
		oday.selectedIndex=mday-1;
	}
	var humDate = new Date(Date.UTC(myear,mmonth,mday,mhour,mminute,0));
	;
	ostamp.value=humDate.getTime()/1000.0;
}

function getPageSize()
{
	var xScroll, yScroll;
  if(window.innerHeight && window.scrollMaxY)
  {
	  xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;

	if(self.innerHeight)
	{	// all except Explorer
			if(document.documentElement.clientWidth)
			{
				windowWidth = document.documentElement.clientWidth;
			}
			else
			{
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
	}
	else if(document.body)
	{ // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
	}

		// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
			pageHeight = windowHeight;
	}
	else
	{
			pageHeight = yScroll;
	}

		// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
			pageWidth = xScroll;
	}
	else
	{
			pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

/*new gallery stuff begin*/
  function galleryShowVideo(video,still,w,h,mid)
  {
    var so = new SWFObject(g["path"]+"/mp.swf", mid, w, h, "8", "#000000");
    so.addParam("scale", "noscale");
    so.addParam("wmode", "opaque");
    so.addVariable("file", video);
    so.addVariable("image",still);
    so.addVariable("autostart",true);
    so.write(mid+'FlashContainer');
  }

  function galleryPreloadImg(mid,imgnum,maxn,glob)
  {
    if(glob[mid][imgnum][4]=='i')
    {
    	var cacheImage = document.createElement('img');
      cacheImage.src = glob[mid][imgnum][0];
    }
    if((imgnum-1) >= 0)
    {
    	if(glob[mid][imgnum-1][4]=='i')
    	{
    	  var cacheImage = document.createElement('img');
        cacheImage.src = glob[mid][imgnum-1][0];
      }
    }
    if((imgnum+1) < maxn)
    {
    	if(glob[mid][imgnum+1][4]=='i')
    	{
    	  var cacheImage = document.createElement('img');
        cacheImage.src = glob[mid][imgnum+1][0];
      }
    }
  }

  function galleryImageChange(mid,imgnum,glob)
  {
  	w = glob[mid][imgnum][1];
    h = glob[mid][imgnum][2];
    maxn=glob[mid].length;
    galleryPreloadImg(mid,imgnum,maxn,glob);
    c=glob[mid+'c']+1;

  	$('#'+mid+'Next').hide();
    $('#'+mid+'Prev').hide();
    $('#'+mid+'Txt').fadeTo(1,0.01);

    $('#'+mid+'Close').hide();
  	$('#'+mid+'Img').fadeOut(100, function(){

  		if(glob[mid][imgnum][4]=='i')
  		{
  		  $('#'+mid+'FlashContainer').hide();
  		  $('#'+mid+'FlashContainer').empty();
  		  $('#'+mid+'Img').attr('src',glob[mid][imgnum][0]);
  		  $('#'+mid+'Title').text(glob[mid][imgnum][3]);
        if(maxn!=1) $('#'+mid+'Count').text(maxn+"/"+c);

        hh = h+40;
        $('#'+mid+'Pop').animate({width : w,height : hh},600,function() {
        if(maxn!=1)
        {
          if(c == maxn)
          {
      	    $('#'+mid+'Prev').width(w);
            $('#'+mid+'Prev').show();
          }
          else
          {
      	    if(c == 1)
            {
        	    $('#'+mid+'Next').width(w);
      	      $('#'+mid+'Next').show();
            }
            else
            {
              $('#'+mid+'Next').width(Math.round(w/2)-2);
              $('#'+mid+'Prev').width(Math.round(w/2)-2);
              $('#'+mid+'Next').show();
              $('#'+mid+'Prev').show();
            }
          }
          $('#'+mid+'Next').height(h);
          $('#'+mid+'Prev').height(h);
        }
        else
        {
          $('#'+mid+'Img').click(function(){galleryOff(mid);});
        }
    	  $('#'+mid+'ImgContainer').width(w);
  	    $('#'+mid+'ImgContainer').height(h);
  	    $('#'+mid+'Img').fadeIn(600,function(){
            $('#'+mid+'Close').show();
            $('#'+mid+'Txt').fadeTo(1,1);
      	  });
    	  });
    	}
    	else
    	{
    		$('#'+mid+'Close').show();
        $('#'+mid+'Title').text(glob[mid][imgnum][3]);
    		hh = h+40;
    		$('#'+mid+'Pop').animate({width : w,height : hh},600,function() {
    		galleryShowVideo(glob[mid][imgnum][0],glob[mid][imgnum][4],glob[mid][imgnum][1],glob[mid][imgnum][2],mid);
    		if(maxn!=1)
        {
          if(c == maxn)
          {
      	    $('#'+mid+'Prev').width(w);
            $('#'+mid+'Prev').show();
          }
          else
          {
      	    if(c == 1)
            {
        	    $('#'+mid+'Next').width(w);
      	      $('#'+mid+'Next').show();
            }
            else
            {
              $('#'+mid+'Next').width(Math.round(w/3)-2);
              $('#'+mid+'Prev').width(Math.round(w/3)-2);
              $('#'+mid+'Next').show();
              $('#'+mid+'Prev').show();
            }
          }
          $('#'+mid+'Next').height(h-40);
          $('#'+mid+'Prev').height(h-40);
        }
    	  $('#'+mid+'ImgContainer').width(w);
  	    $('#'+mid+'ImgContainer').height(h);
        $('#'+mid+'FlashContainer').fadeIn(600,function(){
            if(maxn!=1) $('#'+mid+'Count').text(maxn+"/"+c);
            $('#'+mid+'Txt').fadeTo(1,1);
      	  });
    	  });
    	}
    });
  }

	function galleryOn(mid,imgnum,glob)
	{
		$('body').append('<div class=\"gallerycurtain\" id=\"'+mid+'Curtain\"></div><div class=\"gallerypopcontainer\" id=\"'+mid+'Container\"><div class=\"gallerypop\" id=\"'+mid+'Pop\"><div id=\"'+mid+'Close\" class=\"galleryclose\"><a href=\"javascript:galleryOff(\''+mid+'\')\" title=\"'+glob[mid+'close']+'\"><img src=\"'+glob['path']+'mclose.png\"></a></div><div id=\"'+mid+'ImgContainer\" style=\"position:absolute; overflow:hidden;\"><a id=\"'+mid+'Next\" class=\"gallerynext\" href=\"javascript:galleryNext(\''+mid+'\',g);\" title=\"'+glob[mid+'next']+'\"> </a><a id=\"'+mid+'Prev\" class=\"galleryprev\" href=\"javascript:galleryPrev(\''+mid+'\',g);\" title=\"'+glob[mid+'prev']+'\"> </a></div><img id=\"'+mid+'Img\" src=\"'+glob['path']+'t.gif\" alt=\"\"><div id=\"'+mid+'FlashContainer\"></div><div id=\"'+mid+'Txt\" class=\"gallerytxt\"><div id=\"'+mid+'Title\" class=\"gallerytitle\"> </div><div id=\"'+mid+'Count\" class=\"gallerycount\"> </div><div class=\"clear\"></div></div></div>');
	  glob[mid+'c']=imgnum;
	  s = getPageSize();
	  $('#'+mid+'Curtain').height(s[1]);
	  $('#'+mid+'Curtain').fadeTo(600,0.7,function(){$('#'+mid+'Pop').fadeIn(600,galleryImageChange(mid,imgnum,glob));});
  }

	function galleryOff(mid)
	{
		$('#'+mid+'Next').hide();
    $('#'+mid+'Prev').hide();
    $('#'+mid+'Pop').fadeOut(600,function()
    {$('#'+mid+'Curtain').fadeOut(600,function(){
    	$('#'+mid+'Img').attr('src','');
      $('#'+mid+'FlashContainer').empty();
      $('.gallerycurtain').remove();
      $('.gallerypopcontainer').remove();
     });
    });
	}

	function galleryNext(mid,glob)
	{
    var maxn = glob[mid].length-1;
    var c =  glob[mid+'c']+1;
    if(c > maxn) c=maxn; if(c < 0) c=0;
    glob[mid+'c']=c;
    galleryImageChange(mid,c,glob);
	}

	function galleryPrev(mid,glob)
	{
    var maxn = glob[mid].length;
    var c =  glob[mid+'c']-1;
    if(c > maxn) c=maxn; if(c < 0) c=0;
    glob[mid+'c']=c;
    galleryImageChange(mid,c,glob);
	}
/*new gallery stuff end*/
