/* Global JavaScript Document for Classic Motors */


//  BEGIN: Random image
	function random(howMany) {
		var choice;
		var range = howMany;

		if (Math.random) {
			choice = Math.round(Math.random() * (range-1));
			}
			else {
				var now = new Date();
				choice = (now.getTime() / 1000) % range;
			}
		choice = choice+1;
		return choice;
	}
//  FINISH: Random image


//  BEGIN: popup window
	function PopUpCM(url)
	{
		var xheight = '500';
		var xwidth = '700';
		popupCM = window.open(url,'popupCM','height='+xheight+',width='+xwidth+',scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,status=0,left='+(parseInt((screen.availWidth-xwidth)/2))+',top='+(parseInt(((screen.availHeight-xheight)/2)-30))+'');
		popupCM.document.close();
		popupCM.focus();
	}
//  FINISH: popup window


//  BEGIN: popup photo window
	function PopUpPhoto(img,title,width,height)
	{
		var yheight = (height+45);
		var s1 = "<html><head><title>"+title+"</title><link rel=stylesheet href='libs/style_global.css' type='text/css'>"+
				 "</head><body onBlur='self.close()'>";
		var s2 = "<div><img src='images/"+img+"' border='0' width='"+width+"' height='"+height+"' alt=''></div>";
		var s3 = "<div align='center'><p>[ <a href = '#' onClick='window.close(self);'>close window</a> ]</p></div></body></html>";

		popupphoto = window.open('','','height='+yheight+',width='+width+',scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,status=0,left='+(parseInt((screen.availWidth-width)/2))+',top='+(parseInt(((screen.availHeight-yheight)/2)-30))+'');
		popupphoto.document.write(s1+s2+s3);
		popupphoto.document.close();
	}
//  FINISH: popup photo window

// BEGIN: popup window safety
	function SafetyPopUp(model,which,number)
	{
		PopupImage = "images/model_safety/" + model + "/" + model + "_" + which + "_sm.jpg";
		var s1 = "<html><head><title>Model Safety</title><link rel=stylesheet href='libs/style_global.css' type='text/css' />"+
				 "</head><body onBlur='self.close()'>";
		var s2 = "<div style='position:absolute;top:10px;left:10px;width:320px;height:240px'><img src='"+PopupImage+"' border='0' width='320' height='240' alt='"+featurePopUp[number][0]+"'></div>";
		var s3 = "<div style='position:absolute;top:10px;left:340px;width:290px;height:260px'><h2>"+featurePopUp[number][0]+"</h2><p>"+featurePopUp[number][1]+"</p></div>";
		var s4 = "<div style='position:absolute;bottom:4px;margin-left:35%'><p>[ <a href = '#' onClick='window.close(self);'>close window</a> ]</p></div></body></html>";

		popupsafety = window.open('','','height=280,width=650,scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,status=0,left='+(parseInt((screen.availWidth-650)/2))+',top='+(parseInt(((screen.availHeight-280)/2)-30))+'');
		popupsafety.document.write(s1+s2+s3+s4);
		popupsafety.document.close();
	}


//  BEGIN: popup gallery window
	var firstImg = true
	var X2;
	var Y2;

	function GallerySwap(model,which,X2,Y2)
	{
		this.X2 = X2
		this.Y2 = Y2

		NewImage = "images/model_gallery/" + model + "/" + model + "_" + which + "_sm.jpg";
		PopupImage =  "images/model_gallery/" + model + "/"  + model + "_" + which + "_lg.jpg";

		document.mediumPhoto.width = 257;
		document.mediumPhoto.height = 194;
		document.mediumPhoto.src = NewImage;
		document.getElementById('colorText').innerHTML = '';

		return firstImg = false;
	}

	function GallerySwap2(model,which,X2,Y2,Z2)
	{
		this.X2 = X2
		this.Y2 = Y2

		NewImage = "images/model_colours/" + model + "/" + model + "_" + which + "_sm.jpg";
		PopupImage =  "images/model_colours/" + model + "/"  + model + "_" + which + "_lg.jpg";

		document.mediumPhoto.width = 256;
		document.mediumPhoto.height = 160;
		document.mediumPhoto.src = NewImage;
		document.getElementById('colorText').innerHTML= colourSwatches[Z2];


		return firstImg = false;
	}

	function GallerySwap3(model,which,X2,Y2)
	{
		this.X2 = X2
		this.Y2 = Y2

		NewImage = "images/model_accessories/" + model + "/" + model + "_" + which + "_sm.jpg";
		PopupImage = "images/model_accessories/" + model + "/" + model + "_" + which + "_lg.jpg";

		document.preview.width = 257;
		document.preview.height = 194;
		document.preview.src = NewImage;

		return firstImg = false;
	}

	function GalleryPop(model,X1,Y1)
	{
		if (firstImg == true) { GalleryOpen ('images/model_gallery/' + model + '/' + model + '_01_lg.jpg','',X1,Y1); }
		else { GalleryOpen (PopupImage,'',X2,Y2); }
	}

	function GalleryPop2(model,X1,Y1)
	{
		if (firstImg == true) { GalleryOpen ('images/models/' + model + '_overview.jpg','',X1,Y1); }
		else { GalleryOpen (PopupImage,'',X2,Y2); }
	}

	function GalleryOpen(img,title,width,height)
	{
		var myWidth = width
		var myHeight = (height+50); // adjusts window height

		var LeftPos = (parseInt((screen.availWidth-myWidth)/2));
		var TopPos = (parseInt(((screen.availHeight-myHeight)/2)-40));

		var css_src = 'libs/style_global.css';  // location of css for style


	// only alter if comfortable with js formatting

		var g1 = "<html><head><title>"+title+"</title>"+
				 "<link rel=stylesheet href="+css_src+" type='text/css'>";
		var g2 = "</head><body onBlur='window.close(self);'> <div><img src='"+img+"' border='0' "+
				 "width='"+width+"' height='"+height+"' alt=''></div>";
		var g3 = "<div align='center'><p>[ <a href = '#' onClick='window.close(self);'>"+
				 "close window</a> ]</p></div></body></html>";

		popupgallery = window.open('','popupgallery','height='+myHeight+',width='+myWidth+
					',scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,'+
					'status=0,left='+LeftPos+',top='+TopPos+'');

		popupgallery.document.write(g1+g2+g3);
		popupgallery.document.close();
		popupgallery.focus();

	}
//  FINISH: popup gallery window


//  BEGIN: pulldown menu
	function GoToPage(page) {

		if ( page != "" ) {
			self.location = page;
		}
	}
//  FINISH: pulldown menu


//  BEGIN: Rollover and preload flags
	function newImage(arg) {
		if (document.images) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}
	}
	function changeImages() {
		if (document.images && (preloadFlag == true)) {
			for (var i=0; i<changeImages.arguments.length; i+=2) {
				document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
			}
		}
	}
	var preloadFlag = false;

	function preloadImages() {
		if (document.images) {
			home_over = newImage("images/global_tools/01_on.gif");
			locations_over = newImage("images/global_tools/02_on.gif");
			talk2us_over = newImage("images/global_tools/03_on.gif");
			aboutus_over = newImage("images/global_tools/04_on.gif");
			sitemap_over = newImage("images/global_tools/05_on.gif");
			whatshonda_over = newImage("images/global_tools/05_on.gif");
			specials_over = newImage("images/specials/more_specials_over.gif");
			Submit_over = newImage("images/popups/send_over.gif");
			preloadFlag = true;
		}
	}

	function preloadImages2() {
		if (document.images) {
			car1_over = newImage("images/home/accord_over.gif");
			car2_over = newImage("images/home/civic_over.gif");
			car3_over = newImage("images/home/crv_over.gif");
			car4_over = newImage("images/home/fit_over.gif");
			car5_over = newImage("images/home/stream_over.gif");
		car6_over = newImage("images/home/odyssey_over.gif");

preloadFlag = true;
		}
	}

	function preloadImages3() {
		if (document.images) {
			overview_over = newImage("images/nav_local/model_overview_over.gif");
			gallery_over = newImage("images/nav_local/model_gallery_over.gif");
			spec_over = newImage("images/nav_local/model_spec_over.gif");
			safety_over = newImage("images/nav_local/model_safety_over.gif");
			access_over = newImage("images/nav_local/model_access_over.gif");
			staff_over = newImage("images/nav_local/sales_staff_over.gif");
			order_over = newImage("images/nav_local/form_order_brochure_over.gif");
			request_over = newImage("images/nav_local/form_request_test_over.gif");
			contact_over = newImage("images/nav_local/form_contact_over.gif");
			warranty_over = newImage("images/models/warranty_over.gif");
			preloadFlag = true;
		}
	}

	function preloadImagesGT() {
		if (document.images) {
			company_over = newImage("images/nav_local/about_company_over.gif");
			pos_over = newImage("images/nav_local/about_pos_over.gif");
			sfdo_over = newImage("images/nav_local/about_sfdo_over.gif");
			tobago_over = newImage("images/nav_local/about_tobago_over.gif");
			preloadFlag = true;
		}
	}


	function preloadImagesEssen() {
		if (document.images) {
			deptartment_over = newImage("images/nav_local/svc_dept_over.gif");
			maintenance_over = newImage("images/nav_local/svc_schedule_over.gif");
			faqs_over = newImage("images/nav_local/svc_faq_over.gif");
			staff_over = newImage("images/nav_local/svc_staff_over.gif");
			special_over = newImage("images/nav_local/svc_special_over.gif");
			book_over = newImage("images/nav_local/form_svc_book_over.gif");
			contact_over = newImage("images/nav_local/form_svc_contact_over.gif");
			Partsdepartment_over = newImage("images/nav_local/parts_dept_over.gif");
			PartsSpecials_over = newImage("images/nav_local/parts_special_over.gif");
			order_over = newImage("images/nav_local/form_parts_order_over.gif");
			contactParts_over = newImage("images/nav_local/form_parts_contact_over.gif");
			preloadFlag = true;
		}
	}

	function preloadImagesInterests() {
		if (document.images) {
			history_over = newImage("images/nav_local/tradition_history_over.gif");
			strategy_over = newImage("images/nav_local/tradition_strategy_over.gif");
			environment_over = newImage("images/nav_local/tradition_environment_over.gif");
			preloadFlag = true;
		}
	}

//  FINISH: Rollover and preload flags

