function theflash(movie, width, height) {
    document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '">');
    document.writeln('<param name="movie" value="' + movie + '">');
    document.writeln('<param name="quality" value="high" />');
    document.writeln('<param name="menu" value="false">');
    document.writeln('<param name="wmode" value="transparent">');
    document.writeln('<embed src="' + movie + '" width="' + width + '" height="' + height + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
    document.writeln('</object>');
}

function postcodeMap(postcode) {
    if (navigator.javaEnabled() == true) {
        return 'http://link2.map24.com/?lid=03763162&amp;maptype=JAVA&amp;width0=1500&amp;zip0=' + postcode.replace(' ', '+') + '&amp;country0=GB';
    } else {
        return 'http://www.multimap.com/map/browse.cgi?client=public&amp;db=pc&amp;cidr_client=none&amp;pc=' + postcode.replace(' ', '+');
    }
}

function showContactDetails() {
	if($('contactA').hasClassName('active')) {
		$('contactA').removeClassName('active');
		$('contactNumberContainer').toggle();
	}
	else {
		$('contactA').addClassName('active');
		$('contactNumberContainer').toggle();
	}
}

function clearAllFeatured(){
	var parasa = $A(document.getElementsByClassName('showFeaturedCar'));
	parasa.each(Element.hide);
}

function nextFeaturedCar(){
	clearAllFeatured();
	var currVal = parseInt($('currentCar').value);
	var nextVal = currVal + 1;
	if( nextVal == carArray.length ){
		$('showFeaturedCar'+carArray[0]).show();
		$('currentCar').value=0;
	}else{
		$('showFeaturedCar'+carArray[nextVal]).show();
		$('currentCar').value=nextVal;
	}
}

function prevFeaturedCar(){
	clearAllFeatured();
	var currVal = parseInt($('currentCar').value);
	var prevVal = currVal - 1;

	if( prevVal < 0 ){
		$('showFeaturedCar'+carArray[carArray.length-1]).show();
		$('currentCar').value=carArray.length-1;
	}else{
		$('showFeaturedCar'+carArray[prevVal]).show();
		$('currentCar').value=prevVal;
	}
}

function changeMainCarPic( imgSrc ) {
	$('mainCarPic').src = baseHref + 'images/global_auto/medium/' + imgSrc;
	$('lightboxLink').href = baseHref + 'images/global_auto/large/' + imgSrc
	currentImageURL = imgSrc;
}

function swapSaveRemoveBtns() {
	$('saveCompare').toggle();
	$('removeSaveCompare').toggle();
}

function addToWishList( carId ) {
	var target = baseHref + 'ajax.php';
	var params = 'type=addToWishList&carId=' + carId;

	var myAjax = new Ajax.Request(target,
		{
			method: 'post',
			parameters: params,
			onSuccess: function (request) {
				if ( request.responseText == 'This car is already in your wishlist' || request.responseText == 'You have too many cars in your wish list already. You must delete some before you can add any more.' ) {
					alert( request.responseText );
				} else {
					$('wishList').innerHTML = request.responseText;
					alert( 'This Car has been added to your Wish List' );
					swapSaveRemoveBtns();
					itEvent('saveToFavourites');
				}

			},

			onFailure: function (request) { alert( request.responseText ) }

		});
}

function removeFromWishList( carId ) {

	var target = baseHref + 'ajax.php';
	var params = 'type=removeFromWishList&carId=' + carId;

	var myAjax = new Ajax.Request(target,
		{
			method: 'post',
			parameters: params,
			onSuccess: function (request) {
				if ( request.responseText == 'This car is not in your wishlist' ) {
					alert( 'request.responseText' );
				} else {
					$('wishList').innerHTML = request.responseText;
					alert( 'This Car has been removed from your Wish List' );
					swapSaveRemoveBtns();
				}
			},
			onFailure: function (request) { alert( request.responseText ) }
		});
}

function showLightbox ( ) {
	var items = $('lightboxImageLinks').getElementsByTagName("a");
	myLightbox.start($('lightboxImageLinks').getElementsByTagName("a")[0])
}

function showLightboxImageold ( thisImage ) {
	if ( thisImage ) {
		myLightbox.start($$('#lightboxImageLinks a')[thisImage]);
	} else {
		myLightbox.start($$('#lightboxImageLinks a')[$F('lightBoxImageCounter')]);
	}
}


function showUsedLightboxImage (thisImage) {
	var items = $$('#lightboxImages a');
	var count=0;
	if(thisImage){
		for(var item=0;item<=items.length-1;item++){
			if(items[item].href==thisImage.href){
				count=item;
			}
		}
	}
	myLightbox.start(items[count]);

}


