//AJAX scripts for asyncron stuff begin ===============================
//an AJAX object
function exxite_makeXMLHttp()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}
//Every page has its AJAX object=====================================
var xmlHttp= new exxite_makeXMLHttp();
//AJAX scripts for asyncron stuff end ===============================

var g = new Array();

//layer hiddener
function exxiteShow(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";
	}
}

//text area size changer
function exxiteTSize(id)
{
	if(!document.getElementById) return;
	var o=document.getElementById(id);
	if(o)
	{
		if(o.style.width!="500px")
		{
			o.style.width="500px";
			o.style.height="400px";
		}
		else
		{
			o.style.width="300px";
			o.style.height="120px";
		}
	}
}
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];
}


	function exxiteImageOn(gid,imgname,imgx,imgy,imgtxt)
	{
    c=document.getElementById(gid);
    c.src=imgname;
    c=document.getElementById(gid+'p');
    c.style.width=String(imgx)+'px';
    c=document.getElementById(gid+'t');
    c.innerHTML=imgtxt;
    c=document.getElementById(gid+'c');
    ps=getPageSize();
    c.style.height=ps[1];
    c.style.display="block";
    c=document.getElementById(gid+'cc');
    c.style.display="block";
    c.style.top=document.body.scrollTop+50;
	}

	function exxiteImageOff(gid)
	{
		c=document.getElementById(gid);
    c.src='';
    c=document.getElementById(gid+'t');
    c.innerHTML='';
    c=document.getElementById(gid+'c');
    c.style.display="none";
    c=document.getElementById(gid+'cc');
    c.style.display="none";
	}
/*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']+'/close.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*/

/*accordicon stuff begin*/

function exxiteAccordicon(mid,me,len)
{
	for(i=0; i<len; i++)
  {
  	if($('#'+mid+i).hasClass('open'))
  	{
  		$('#'+mid+i).removeClass('open');
  		$('#'+mid+i+'c').slideUp('slow');
  	}
  }
  $('#'+mid+me).addClass('open');
  $('#'+mid+me+'c').slideDown('slow');
}

/*accordicon stuff end*/
/* tab stuff begin*/
function exxiteTab(prefix,me,maxn)
{
  for(var i=0; i < maxn; i++)
  {
    if(i != me)
    {
      $('#'+prefix+String(i)).toggleClass('seltab',false);
      $('#'+prefix+String(i)).toggleClass('tab',true);
      $('#t'+prefix+String(i)).toggleClass('seltabpanel',false);
      $('#t'+prefix+String(i)).toggleClass('tabpanel',true);
    }
    else
    {
      $('#'+prefix+String(i)).toggleClass('tab',false);
      $('#'+prefix+String(i)).toggleClass('seltab',true);
      $('#t'+prefix+String(i)).toggleClass('tabpanel',false);
      $('#t'+prefix+String(i)).toggleClass('seltabpanel',true);
    }
  }
}
/* tab stuff end*/

/*linkrotator begin*/
function theRotator()
{
	$('div.rotator ul li').css({opacity: 0.0});
	$('div.rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()',6000);
}

function rotate()
{
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
}
/*linkrotator end*/
