$(document).ready(function(){
				$("#Hidden").load("includes/blocs.ajax.contentloader.php?QuoteForms=1");
				$("#Hidden3").load("includes/blocs.ajax.contentloader.php?ContactForm=1");
				$("#Pulldown").click(
						function(){	
							$("#Hidden").slideToggle("slow");
						});
				$("#Pulldown2").click(
						function(){	
							$("#Hidden").slideToggle("slow");
						});   
				$("#Pulldown3").click(
							function(){	
								$("#Hidden3").slideToggle("slow");
							});
				var tabContainers = $('div.tabs table td > div');
    
				$('div.tabs table td ul.tabNavigation a').click(function () {
					tabContainers.hide().filter(this.hash).show();
					
					$('div.tabs table td ul.tabNavigation a').removeClass('selected');
					$(this).addClass('selected');
					
					return false;
				}).filter(':first').click();
			});



var req;


function DisplayProductCategory(categoryid,sortby,pagenumber){
	//alert(categoryid);
	myFullURL = "/includes/blocs.controller.product.php?Display=1&categoryid="+categoryid+"&sortby="+sortby+"&pagenumber="+pagenumber;
	ResponseContainer = 'ProductCategory'+categoryid;
	//alert(document.getElementById(ResponseContainer).innerHTML);
	AJAX_Controller(myFullURL,ResponseContainer);	
}

function AJAX_Controller(myFullURL,ResponseContainer,RedirectHome){
var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function(){
	if(xmlHttp.readyState==4){
		var response = xmlHttp.responseText;
		
		parent.document.getElementById(ResponseContainer).innerHTML=response;
		if(RedirectHome){
			location.href='/admin/';
		}
		changeInputs();
		}
	}
	xmlHttp.open("GET",myFullURL,true);
	xmlHttp.send(null);
}


function navigate(month,year,evt) {
	setFade(0);
	var url = "/includes/blocs.calendar.php?month="+month+"&year="+year+"&event="+evt;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}

function callback() {	
	if(req.readyState == 4) {
		var response = req.responseXML;	
		var resp = response.getElementsByTagName("response");
		getObject("calendar").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		
		fade(100);
	}
}

function getObject(obj) {
	var o;
	if(document.getElementById) o = document.getElementById(obj);
	else if(document.all) o = document.all.obj;	
	return o;	
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		//amt += 10;
		//setTimeout("fade("+amt+")", 5);
    }
}

function setFade(amt) {
	var obj = getObject("calendar");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
}

function showJump(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var jump = document.createElement("div");
	jump.setAttribute("id","jump");
	jump.style.position = "absolute";
	jump.style.top = curtop+15+"px";
	jump.style.left = curleft+"px";
	var output = '<select id="month">\n';
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var n;
	for(var i=0;i<12;i++) {
		n = ((i+1)<10)? '0'+(i+1):i+1;
		output += '<option value="'+n+'">'+months[i]+'  </option>\n';
	}
	output += '</select> \n<select id="year">\n';
	for(var i=0;i<=15;i++) {
		n = (i<10)? '0'+i:i;
		output += '<option value="20'+n+'">20'+n+'  </option>\n';
	}
	output += '</select> <a href="javascript:jumpTo()"><img src="/images/system/calGo.gif" alt="go" /></a> <a href="javascript:hideJump()"><img src="/images/system/calStop.gif" alt="close" /></a>';
	jump.innerHTML = output;
	document.body.appendChild(jump);
}

function hideJump() {
	document.body.removeChild(getObject("jump"));	
}

function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
}


function ShowOptionPanel_Site(Count,OptionID,uniqueID){
	
	for(i=1;i<=Count;i++){
		document.getElementById('PanelButton'+i+':'+uniqueID).className='PanelButton';
		document.getElementById('PanelOption'+i+':'+uniqueID).className='PanelOption';
	}

	document.getElementById('PanelButton'+OptionID+':'+uniqueID).className='PanelButtonOn';
	document.getElementById('PanelOption'+OptionID+':'+uniqueID).className='PanelOptionOn';
}


function ShowStoryPanel_Site(Count,OptionID,uniqueID){
	myHTML='Pages:  ';
	for(i=1;i<=Count;i++){
		document.getElementById('PanelStory'+i+':'+uniqueID).className='PanelStory';
	}
	document.getElementById('PanelStory'+OptionID+':'+uniqueID).className='PanelStoryOn';
	if(OptionID>1){
		myHTML += "<button class=MenuButton  onclick=\"StoryPanel_Control("+Count+",'Back','"+uniqueID+"');\">&nbsp;<&nbsp;</button>";
	}
	for(i=1;i<=Count;i++){
		myHTML += "<button   onclick=\"ShowStoryPanel_Site("+Count+","+i+",'"+uniqueID+"');\"  ";
		myHTML += (i==OptionID)?' class=MenuButtonActive ': ' class=MenuButton';
		myHTML += ">&nbsp;"+i+"&nbsp;</button>";
	}
	
	if(OptionID<Count){
	myHTML += "<button class=MenuButton onclick=\"StoryPanel_Control("+Count+",'Next','"+uniqueID+"');\">&nbsp;>&nbsp;</button>";
	}
	document.getElementById('storyButtons'+uniqueID).innerHTML=myHTML;
}

function StoryPanel_Control(Count,Direction,uniqueID){
	for(i=1;i<=Count;i++){
		if(document.getElementById('PanelStory'+i+':'+uniqueID).className=='PanelStoryOn'){
			currentID = i;
		}
		document.getElementById('PanelStory'+i+':'+uniqueID).className='PanelStory';
	}

	nextID = (currentID == Count)?1:currentID+1;
	backID = currentID-1;
	if(Direction=='Next'){
		ShowStoryPanel_Site(Count,nextID,uniqueID);
	}else{
		ShowStoryPanel_Site(Count,backID,uniqueID);
	}
}



function ShowAlertBox(message,closeit){
	if(!closeit){
	//document.getElementById('AlertTable').style.display='';
	document.getElementById('AlertWindow').style.width='40%';
	document.getElementById('AlertWindow').style.left='30%';
	document.getElementById('AlertWindow').style.top='50%';
	document.getElementById('AlertWindow').style.paddingTop='20px';
	document.getElementById('AlertWindow').style.paddingBottom='20px';
	
	document.getElementById('AlertWindow').style.border='10px solid #ff5505';
	document.getElementById('AlertWindow').style.backgroundColor='#f1f1f1';
	document.getElementById('AlertWindow').style.textAlign='center';
	document.getElementById('AlertWindow').innerHTML = message;
	}else{
	document.getElementById('AlertWindow').style.width='0px';
	document.getElementById('AlertWindow').style.height='0px';
	document.getElementById('AlertWindow').style.border='0px solid gray';
	document.getElementById('AlertWindow').innerHTML = '';
	}
}





function changeInputs()
	{
	var els = document.getElementsByTagName('input');
	var elsLen = els.length;
	var i = 0;
	for ( i=0;i<elsLen;i++ )
		{
			if ( els[i].getAttribute('type') )
			{
				if ( els[i].getAttribute('type') == "text" )
				els[i].className = 'text';
			else
				els[i].className = 'button';
			}
		}
	}



function ShowGalleryImage(ImageID,ModuleID){
	document.getElementById('PreviewImage'+ModuleID).innerHTML='<img style=\"border:2px solid white;\" id=GalImage name=GalImage src=\"/images/' + ImageID + '\">';
	//document.getElementById('GalImage').style.width = 150;
	//document.getElementById('GalImage').style.height = 75;
	
	
	var isIE = document.all?true:false;
	if (!isIE) document.captureEvents(Event.MOUSEMOVE);

  	var _x;
  	var _y;
	  if (!isIE) {
	    _x = e.pageX;
	    _y = e.pageY;
	  }
	  if (isIE) {
	    _x = event.clientX + document.body.scrollLeft;
	    _y = event.clientY + document.body.scrollTop;
	  }

	  document.getElementById('PreviewImage').style.left = _x;
	  document.getElementById('PreviewImage').style.top = _y;
}


function WriteGallery(galleryID,myType){
	if(myType=="h"){
	myFileID = '/includes/FlashGallery_H.swf?XMLURL=/includes/blocs.xml.gallery.php?galleryid='+galleryID;
	myWidth = '520px';
	myHeight = '320px';
	}else{
	myFileID = '/includes/FlashGallery.swf?XMLURL=/includes/blocs.xml.gallery.php?galleryid='+galleryID;
	myWidth = '640px';
	myHeight = '390px';
	}
	myVars = '';
	myObject='<br><center><object style="margin-top:5px;z-index:200;display:inline;width:' + myWidth +';height:' + myHeight +'"  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="150" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="middle">';
	myObject+='<param name="allowScriptAccess" value="sameDomain" />';
	myObject+='<PARAM NAME=wmode VALUE=transparent>';
	myObject+='<param name="movie" value="'+ myFileID +'" /><param name="quality" value="high" />';
	myObject+='<embed width="' + myWidth + '" height="' + myHeight +'"  wmode="transparent" src="'+ myFileID +'" quality="high" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	myObject+='</object>';
	document.write(myObject);
}

function MenuOver(DivID){
	myDiv = document.getElementById(DivID);
	if (myDiv){
		myContent = document.getElementById(DivID).innerHTML;
		document.getElementById('SubMenuDiv').innerHTML = myContent;
		document.getElementById('SubMenuDiv').style.height='20px';
		
	}else{
		document.getElementById('SubMenuDiv').innerHTML = '';
		document.getElementById('SubMenuDiv').style.backgroundColor='';
		document.getElementById('SubMenuDiv').style.height='0px';
	}
}

function moveHandler(e){
      if (e == null) { e = window.event } 
      if (e.button<=1&&dragOK){
         savedObject.style.left=e.clientX-dragXoffset+'px';
         savedObject.style.top=e.clientY-dragYoffset+'px';
        
         return false;
      }
   }

   function cleanup(e) {
      document.onmousemove=null;
      document.onmouseup=null;
      //savedObject.style.cursor=orgCursor;
      dragOK=false;
    
   }


function dragHandler(e){
   	
      var htype='-moz-grabbing';
      if (e == null) { e = window.event; htype='move';} 
      var target = e.target != null ? e.target : e.srcElement;
     // orgCursor=target.style.cursor;
    // alert();
     if (target.className=="Movable"||target.id=="ImageGallery_Preview") {
        savedObject=target;

         dragOX =  parseInt(target.style.left);
         dragOY =  parseInt(target.style.top);
         dragOX = isNaN(dragOX) ? 0 : dragOX;
         dragOY = isNaN(dragOY) ? 0 : dragOY;
         
         target.style.zIndex=100;
       //  target.style.cursor=htype;
         dragOK=true;
       //  alert(e.clientX);
         dragXoffset=e.clientX-dragOX;//-parseInt(target.style.left);
         dragYoffset=e.clientY-dragOY;//-parseInt(target.style.top);
         //dragXoffset=0;
        //dragYoffset=0;
        document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      } else if (target.id=="ImageGallery_Preview") {
	savedObject=target;
	if(target.style.left){
		dragOX =  parseInt(target.style.left);
		dragOY =  parseInt(target.style.top);
		}else{
		dragOX = 0;
		dragOY = 10;    
		}
	dragOY =  parseInt(target.style.top);
	target.style.zIndex=100;
	//target.style.cursor=htype;
	dragOK=true;
	dragXoffset=e.clientX-dragOX;
	dragYoffset=e.clientY-dragOY;
        document.onmousemove=SlideHandler;
	document.onmouseup=cleanupSlider;
	return false;
	}
     
   }
   
document.onmousedown=dragHandler;

function StopGallery(){
	clearInterval(myInterval);
}
function SlideGallery(direction){
	if(direction=='up'){
		myInterval = setInterval('MoveGallery(1)',10);
	}else{
		myInterval = setInterval('MoveGallery(0)',10);
	}
}

function MoveGallery(isUp){
	top_orgin = parseInt(document.getElementById('ImageGallery_Thumbs').style.top);
	if(isUp){
		document.getElementById('ImageGallery_Thumbs').style.top = (top_orgin+2)+'px';
	}else{
		document.getElementById('ImageGallery_Thumbs').style.top = (top_orgin-2)+'px';
	}
}

function searchKeyPress(e)
        {
                if (window.event) { e = window.event; }
                if (e.keyCode == 13)
                {
			value = document.getElementById('searchterm').value;
			searchResults(value);
                }
		
        }
function searchButtonPress(){
	
	 	value = document.getElementById('searchterm').value;
		searchResults(value);
		
	}
	
function searchResults(value){
	valueEncode = escape(value);
	location.href='/?t=special&q='+valueEncode;
	}
function Add_ShoppingCart(){
	//myFullURL = "/includes/blocs.cart.processor.php?UpdateCart=1";
	//ResponseContainer = 'ShoppingCartDiv';
	//AJAX_Controller(myFullURL,ResponseContainer);	

	ShowAlertBox('Quote Updated <br> <A href="/?t=special&cart=1">View Quote</a>',0);
	setTimeout('ShowAlertBox(\'\',1)',3000);
	document.getElementById('CartButton').innerHTML = "<button class=MenuButton onclick=\"location.href='/?t=special&cart=1';\"> YOUR QUOTE</button>";
	

}

function Update_CartItem(ItemID,Quantity){
	myFullURL = "/includes/blocs.cart.processor.php?UpdateItem=1&ItemID="+ItemID+"&Quantity="+Quantity;
	ResponseContainer = 'ShoppingCartInfo';
	AJAX_Controller(myFullURL,ResponseContainer);	

}
function Remove_CartItem(ItemID){
	myFullURL = "/includes/blocs.cart.processor.php?RemoveItem=1&ItemID="+ItemID;
	ResponseContainer = 'ShoppingCartInfo';
	AJAX_Controller(myFullURL,ResponseContainer);	

}


function initclock(){
  clock();
  setInterval(clock,1000);
}
function clock(){
  var now = new Date();
  var ctx = document.getElementById('clock').getContext('2d');
  ctx.save();
  ctx.clearRect(0,0,60,60);
  ctx.translate(30,30);
  ctx.scale(0.4,0.4);
  ctx.rotate(-Math.PI/2);
  ctx.strokeStyle = "black";
  ctx.fillStyle = "white";
  ctx.lineWidth = 1;
  ctx.lineCap = "round";

  // Hour marks
  ctx.save();
  ctx.strokeStyle = "#fff";
  ctx.fillStyle = "#fff";
  for (i=0;i<12;i++){
    ctx.beginPath();
    ctx.rotate(Math.PI/6);
    ctx.moveTo(50,0);
    ctx.lineTo(60,0);
    ctx.stroke();
  }
  ctx.restore();

  // Minute marks
  ctx.save();
  ctx.strokeStyle = "#fff";
  ctx.fillStyle = "#fff";
  ctx.lineWidth = 1;
  for (i=0;i<60;i++){
    if (i%5!=0) {
      ctx.beginPath();
      ctx.moveTo(56,0);
      ctx.lineTo(60,0);
      ctx.stroke();
    }
    ctx.rotate(Math.PI/30);
  }
  ctx.restore();
  
  var sec = now.getSeconds();
  var min = now.getMinutes();
  var hr  = now.getHours();
  hr = hr>=12 ? hr-12 : hr;

  ctx.fillStyle = "black";

  // write Hours
  ctx.save();
  ctx.rotate( hr*(Math.PI/6) + (Math.PI/360)*min + (Math.PI/21600)*sec )
  ctx.strokeStyle = "#fff";
  ctx.fillStyle = "#fff";
  ctx.lineWidth = 4;
  ctx.beginPath();
  ctx.moveTo(0,0);
  ctx.lineTo(35,0);
  ctx.stroke();
  ctx.restore();

  // write Minutes
  ctx.save();
  ctx.rotate( (Math.PI/30)*min + (Math.PI/1800)*sec )
  ctx.strokeStyle = "#fff";
  ctx.fillStyle = "#fff";
  ctx.lineWidth = 2;
  ctx.beginPath();
  ctx.moveTo(0,0);
  ctx.lineTo(45,0);
  ctx.stroke();
  ctx.restore();
  
  // Write seconds
  ctx.save();
  ctx.rotate(sec * Math.PI/30);
  ctx.strokeStyle = "#fff";
  ctx.fillStyle = "#fff";
  ctx.lineWidth = 1;
  ctx.beginPath();
  ctx.moveTo(0,0);
  ctx.lineTo(50,0);
  ctx.stroke();
  
  // Center circle
   ctx.fillStyle = "#c8c8c8";
  ctx.beginPath();
  ctx.arc(0,0,4,0,Math.PI*2,true);
  ctx.fill();


  ctx.fillStyle = "#c8c8c8";
  ctx.arc(0,0,3,0,Math.PI*2,true);
  ctx.fill();
  ctx.restore();

  ctx.beginPath();
  ctx.lineWidth = 4;
  ctx.strokeStyle = '#f4f4f4';
  ctx.arc(0,0,66,0,Math.PI*2,true);
  ctx.stroke();

  ctx.restore();
}

