//SmartDRIVE Website Management
// (C) TREADY 2008


maxBanner = 6;
bannerFirstWait = 3.5;
bannerWait = 10;
bannerSpeed = 2.5;

previousBanner = maxBanner;

function runBannerSwap(){
	
	nextBanner = currentBanner +1;
	if(nextBanner > maxBanner){
		nextBanner = 1;
	}
	
	document.getElementById('banner' + currentBanner).style.zIndex = 100;
	document.getElementById('banner' + nextBanner).style.zIndex = 101;
	
	document.getElementById('banner' + previousBanner).style.display = "none";
	document.getElementById('banner' + previousBanner).style.zIndex = 100 - previousBanner;
	
	
	Effect.Appear('banner'  + nextBanner,{duration: bannerSpeed});
	
	setTimeout("runBannerSwap()", (bannerWait * 1000));
	
	previousBanner = currentBanner;
	currentBanner = nextBanner;
}

function setupBannerSwap(){
	
	if(currentBanner < 1){
		currentBanner = 1;
	}
	
	previousBanner = currentBanner - 1;
	if(previousBanner == 0){
		previousBanner = maxBanner;
	}
	document.getElementById('banner' + currentBanner).style.zIndex = 100;
	document.getElementById('banner' + previousBanner).style.display = "none";
	document.getElementById('banner' + previousBanner).style.zIndex = 100 - previousBanner;
	
	setTimeout("runBannerSwap()", (bannerFirstWait * 1000));
	
}




//############ AJAX WEB STATS

function WS(page){
	pageTracker._trackPageview('/' + page);
}


function WS_photo(photoid){
	pageTracker._trackPageview('/gallery_photo_' + photoid + '.html');
}

//############ SEARCH SYSTEM
	  	var siteSearchOpen;
		siteSearchOpen = false;
		function SitePerformSearch(){
			if(siteSearchOpen == false){
				siteSearchOpen = true;
				Effect.Appear('siteSearchContainer',{duration: 1.0, afterFinish:siteRunSearch()});
				document.getElementById('siteSearchResults').style.display = 'none';
				
				new Effect.Appear('siteSearchLoading', {duration:1.5});
				new Draggable('siteSearchContainer',{handle: 'searchHold'});
				
				
			}else{
				Effect.Appear('siteSearchLoading',{duration: 0.5, afterFinish: function(run){
				  setTimeout('siteRunSearch()',1000);
				  
				  }});
				
			}
		}
		

		function siteRunSearch(){
			
			new Ajax.Updater('siteSearchResults', 'ajax/search.php?search=' + document.getElementById('siteSearchPhrase').value, {   method: 'get',onComplete: function(fade) {
					Effect.Appear('siteSearchResults',{delay: 1.5, duration: 1.0});
					new Effect.Fade('siteSearchLoading', {duration:1.5});

				} });
		}
		function SiteSearchClose(){
			
			siteSearchOpen = false;
			Effect.Fade('siteSearchContainer',{duration: 1.0, afterFinish: function(hide){
			document.getElementById('siteSearchResults').style.display = 'none';
			}});
		}
		function siteSearchEnter(e){
			var keynum;
			
			if(window.event)
			  {
			  keynum = e.keyCode;
			  }
			else if(e.which)
			  {
			  keynum = e.which;
			  }
			
			if(keynum == 13){
				SitePerformSearch();
				return false;
			}else{
				return true;
			}
		}
		
		
//############# STYLE SWITCHING

function PerformStyleSwap(style){
				var styleName;
				
				new Ajax.Request('ajax/save_style.php?style=' + style,
				  {
					method:'get',
					onSuccess: function(transport){
					  styleName = transport.responseText;
					 	if(styleName != ""){
							document.getElementById('css_colour').href = "style/" + styleName +  "/colour.css";
						}
					},
					onFailure: function(){ alert('Sorry but we cannot swap styles at this time. Please try again later.') }
				  });

				
				
			}
			
//############# SHOW/HIDE login box		
function toggleLogin(){
	
	if(LoginOpen == false){
		$('contact-box').style.display = 'block';
		new Effect.Move('contact-box-mover', { x: 0, y: 0, mode: 'absolute' });
		LoginOpen = true;
	}else{
		
		new Effect.Move('contact-box-mover', { x: 0, y: -198, mode: 'absolute', afterFinish: function(){$('contact-box').style.display = 'none';} });
		LoginOpen = false;
	}

}

//############# PNG FIXING CODE
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function OpenLogin(){
  
  if($('login').style.display == 'none'){
    	new Ajax.Updater('login', '/ajax/loginbox.php', { method: 'post', onSuccess: function (){
				  new Effect.Opacity('login',{ duration: 0.5, transition: Effect.Transitions.linear, from: 0, to: 1.0}); 
		}});

  }
  
}


//############# MINI CALENDAR UPDATE
function calUpdate(date){
	/*new Effect.Opacity('minicalendar',{ duration: 0.5, transition: Effect.Transitions.linear, from: 1.0, to: 0, afterFinish: function() {
		new Ajax.Updater('minicalendar', '/ajax/minicalendar.php?date=' + date, { method: 'post', onSuccess: function (){
																													  new Effect.Opacity('minicalendar',{ duration: 0.5, transition: Effect.Transitions.linear, from: 0, to: 1.0}); 
																													   
																													   }});																															
																																	} });
	*/
}
