var ROOTURL="http://www.emguk.com/";
//var ROOTURL="http://localhost/COM/MAKE/evolutiondirect/";

function roll_over(image_id,change_to) {
   var this_img=document.getElementById(image_id);
   this_img.src=ROOTURL+change_to;
}
function post_form($form_id){document.getElementById($form_id).submit();}
function add_event($object,$type,$fn){ 
   if($object.attachEvent){ 
      $object['e'+$type+$fn] = $fn; 
      $object[$type+$fn] = function(){$object['e'+$type+$fn]( window.event );} 
      $object.attachEvent( 'on'+$type, $object[$type+$fn] ); 
   }else{
      $object.addEventListener($type,$fn,false); 
   }
}
function remove_event($object,$type,$fn){
   if($object.detachEvent){
      $object.detachEvent('on'+$type,$object[$type+$fn]);
      $object[$type+$fn]=null;
   }else{
      $object.removeEventListener($type,$fn,false);
   }
} 
function elements_with_class($elem,$tag_name,$class_name){
   var $arr_elems=($tag_name=="*" && document.all)? document.all : $elem.getElementsByTagName($tag_name);
   var $found = new Array();
   for($i=0;$i<$arr_elems.length;$i++){  
      if($arr_elems[$i].className==$class_name) $found.push($arr_elems[$i]);
   }
   return ($found);
}
function http_location($filename){
   window.location=$filename;
}
function confirm_action($message,$url) {
	var $answer=confirm($message);
	if($answer)window.location($url);
}
function picture_window($url,$width,$height,$window) {
   window.open($url+'&width='+$width+'&height='+$height,$window,"width="+$width+",height="+$height+",scrollbars=no,left=100,top=100");
}
function external_links(){
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")anchor.target = "_blank";
   }
}

function enlarge_image($path,$width,$height) {
   window.open('enlarge_image.php?path='+$path,'enlargement',"width="+$width+",height="+$height+",scrollbars=no,left=100,top=100");
}

function show_next_slide(){
   $hidden=elements_with_class(document,"*",'carslide');
	 for($i=0;$i<$hidden.length;$i++){
	    if($hidden[$i].style.display=='block')$current=$i;
	 }
	 if(!$current)$current=0;
	 $total=$hidden.length-1;
	 if($current==$total){
	    $change_to=0;
	 }else{
	    $change_to=$current+1;
	 }
	 for($i=0;$i<$hidden.length;$i++){
	    $hidden[$i].style.display='none'
	 }
	 $hidden[$change_to].style.display='block';
}

function load_makes($make){
   $url=ROOTURL+'load_car_make.php?make='+$make;
   ajax_do(ajax_init(),$url,display_makes,'GET');
}

function display_makes($xh_obj){
   $response=$xh_obj.responseText;
	 document.getElementById('carslides').innerHTML=$response;
   
}

function load_map($map_id) {
   $elem=document.getElementById($map_id);
	 if (GBrowserIsCompatible()) {
      var $map = new GMap2($elem);
      $point=new GLatLng(53.78588,-1.78738);
      $map.setCenter($point,13);
      var $marker = new GMarker($point);
      $map.addOverlay($marker);
      $marker.openInfoWindowHtml('<span style="color:#000000"><strong>Evolution Direct (UK) Ltd</strong><br />Our Location in Bradford, West Yorkshire</span>');
      $map.addControl(new GLargeMapControl());
   }
	 return true;
}

function initialise(){
   image_rotate();
	 external_links();
}
window.onload=initialise;

function start_side_panels($num){
   image_rotate();
	 external_links();
   setTimeout('swap_panel(2,'+$num+')',5000);
}

function swap_panel($which,$total){
   $panels=elements_with_class(document,"*",'sidepanel');
	 for($i=0;$i<$panels.length;$i++){
	    $panels[$i].style.display='none';
	 }
	 document.getElementById('sidepanel'+$which).style.display='block';
	 
	 if($which==$total){$which=1;}else{$which++;}
   setTimeout('swap_panel('+$which+','+$total+')',5000);
}

function show_car_photo($num){
   $cars=elements_with_class(document,"*",'largecarphoto');
	 for($i=0;$i<$cars.length;$i++){
	    $cars[$i].style.display='none';
	 }
	 document.getElementById('largecarphoto'+$num).style.display='block';
}

function show_submenu($which){
   $panels=elements_with_class(document,"*",'submenu');
   $on_panels=elements_with_class(document,"*",'submenu showthisone');
	 for($i=0;$i<$panels.length;$i++){
	    $panels[$i].style.display='none';
	 }
	 for($i=0;$i<$on_panels.length;$i++){
	    if($on_panels[$i])$on_panels[$i].style.display='none';
	 }
	 if(!$which){
	    if($on_panels[0])$on_panels[0].style.display='block';
	    return true;
	 }
	 document.getElementById('submenu'+$which).style.display='block';
	 return true;
}


function image_rotate(){
   setTimeout('swap_image(2)',6000);
}

function swap_image($onfront){
   for($i=1;$i<=3;$i++){
	    document.getElementById('headersplash'+$i).style.display='none';
	 }
	 $elem=document.getElementById('headersplash'+$onfront);
	 $elem.style.display='block';
	 if($onfront==3){ $onfront=1; }else{ $onfront++; }
   setTimeout('swap_image('+$onfront+')',6000);
}
