/*
	Client : Nice cars
	Coder : Graham Holden, torpedo group ltd.
	date : 6/6/08
	
	This is used to control the animation aspects of the content.
*/

var url_full = 'http://www.nicecarcompany.co.uk/';
var navigation = false;
var news = false;
var over_arrow = false;

function expand(dir,layer,distance){ // a general function that expands and contracts content
	if(dir == 'down'){
 		new Effect.Move(layer, { 
 			x: 0, 
 			y: distance,
 			duration: 1.0
 		});
 		
 	}else if(dir == 'up'){
 		new Effect.Move(layer, { 
 			x: 0, 
 			y: 0 - distance,
 			duration: 1.0
 		});

 	}
}
 
function news_expand(dir,distance){ // function used to expand the news section
 	if(news == false && dir == 'down'){
 		expand('down','footer',distance); 
 		expand('down','offers',distance);
 		news = true;
 		$('news_button').setAttribute('src','assets/templates/site/img/arrow_button_up.gif');
 	}else if(news == true && dir == 'up'){
 		expand('up','footer',distance);
 		expand('up','offers',distance);
 		news = false;
 		$('news_button').setAttribute('src','assets/templates/site/img/arrow_button.gif');

 	}else if(dir == 'arrow'){
 		//alert($('news_button').readAttribute('src'));
 		if($('news_button').readAttribute('src') == 'assets/templates/site/img/arrow_button.gif'){
 			expand('down','footer',distance); 
 			expand('down','offers',distance);
 			$('news_button').setAttribute('src','assets/templates/site/img/arrow_button_up.gif');
 			news = true;
 		}else{
 			expand('up','footer',distance); 
 			expand('up','offers',distance);
 			$('news_button').setAttribute('src','assets/templates/site/img/arrow_button.gif');	
 			news = false;	
 		}
 	}
}


function news_expand_scroll(dir,distance){ // function used to expand the news section
 	if(news == false && dir == 'down'){
 		expand('down','footer_scroll',distance); 
 		expand('down','offers_scroll',distance);
 		news = true;
 		$('news_button').setAttribute('src','assets/templates/site/img/arrow_button_up.gif');
 	}else if(news == true && dir == 'up'){
 		expand('up','footer_scroll',distance);
 		expand('up','offers_scroll',distance);
 		news = false;
 		$('news_button').setAttribute('src','assets/templates/site/img/arrow_button.gif');

 	}else if(dir == 'arrow'){
 		//alert($('news_button').readAttribute('src'));		
 		if($('news_button').readAttribute('src') == 'assets/templates/site/img/arrow_button.gif'){
 			expand('down','footer_scroll',distance); 
 			expand('down','offers_scroll',distance);
 			$('news_button').setAttribute('src','assets/templates/site/img/arrow_button_up.gif');
 			news = true;
 			// $('news_scroll').scrollTo();
 		}else{
 			expand('up','footer_scroll',distance); 
 			expand('up','offers_scroll',distance);
 			$('news_button').setAttribute('src','assets/templates/site/img/arrow_button.gif');	
 			news = false;	
 		}
 	}
}
 
 
function navigation_expand(dir,distance){ // function used to expand the navigation section
    if(navigation == false && dir == 'down'){
 		expand('down','content',distance); 
 		expand('down','news',distance); 
 		expand('down','under_news',distance); 
 		expand('down','offers',distance); 
 		expand('down','footer',distance);
 		navigation = true;
 	}else if(navigation == true && dir =='up'){
 		expand('up','content',distance); 
 		expand('up','news',distance); 
 		expand('up','under_news',distance); 
 		expand('up','offers',distance); 
 		expand('up','footer',distance);
 		navigation = false;
				
		$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
 	}
 	
}


function navigation_expand_range(dir,distance){ // function used to expand the navigation section for when it is a scroll page
    if(navigation == false && dir == 'down'){
 		expand('down','content_vehicles',distance); 
 		expand('down','news',distance); 
 		expand('down','under_news',distance); 
 		expand('down','offers',distance); 
 		expand('down','footer',distance);
 		navigation = true;
 	}else if(navigation == true && dir =='up'){
 		expand('up','content_vehicles',distance); 
 		expand('up','news',distance); 
 		expand('up','under_news',distance); 
 		expand('up','offers',distance); 
 		expand('up','footer',distance);
 		navigation = false;

		$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
 	}
 	
}


function navigation_expand_range_list(dir,distance){ // function used to expand the navigation section for when it is a scroll page
    if(navigation == false && dir == 'down'){
 		expand('down','content_range',distance); 
 		expand('down','news',distance); 
 		expand('down','under_news',distance); 
 		expand('down','offers',distance); 
 		expand('down','footer',distance);
 		navigation = true;
 	}else if(navigation == true && dir =='up'){
 		expand('up','content_range',distance); 
 		expand('up','news',distance); 
 		expand('up','under_news',distance); 
 		expand('up','offers',distance); 
 		expand('up','footer',distance);
 		navigation = false;

		$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
 	}
 	
}

function navigation_expand_scroll(dir,distance){ // function used to expand the navigation section for when it is a scroll page
    if(navigation == false && dir == 'down'){
 		expand('down','content_scroll',distance); 
 		expand('down','news_scroll',distance); 
 		expand('down','under_news_scroll',distance); 
 		expand('down','offers_scroll',distance); 
 		expand('down','footer_scroll',distance);
 		navigation = true;
 	}else if(navigation == true && dir =='up'){
 		expand('up','content_scroll',distance); 
 		expand('up','news_scroll',distance); 
 		expand('up','under_news_scroll',distance); 
 		expand('up','offers_scroll',distance); 
 		expand('up','footer_scroll',distance);
 		navigation = false;

		$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
		$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
 	}
 	
}



function arrowClick(event){

	var arrow_clicked = Event.element(event).id;
 
	var  id = Event.element(event).id;
	
	switch(id){
		case 'arrow_1':
			appear_id = 'cars';
		break;
		
		case 'arrow_2':
			appear_id = 'bikes';		
		break;
		
		case 'arrow_3':
			appear_id = 'commercial';		
		break;
		
	}
	
	
	if(navigation == true){
		time = 0.0;
	}else{
		time = 0.0;
	} 
	if(Event.element(event).src == url_full+'assets/templates/site/img/navigation/arrow.gif'){
	
		$('white_out').setOpacity(0.0);
		$('white_out').setStyle({
 		display:'none'
		});

		Effect.Fade('bikes',{ duration: 0.0 });
		Effect.Fade('cars',{ duration: 0.0 });
		Effect.Fade('commercial',{ duration: 0.0 });
		Effect.Appear(appear_id, { duration: time });
		
		
		switch(id){
			case 'arrow_1':
				$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow_up.gif');
				$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
				$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
			break;
		
			case 'arrow_2':
				$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
				$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow_up.gif');
				$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');		
			break;
		
			case 'arrow_3':
				$('arrow_1').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
				$('arrow_2').setAttribute('src','assets/templates/site/img/navigation/arrow.gif');
				$('arrow_3').setAttribute('src','assets/templates/site/img/navigation/arrow_up.gif');			
			break;
		
		}
					
		if(template == 'range'){
			navigation_expand_range('down',210);
		}else if(template == 'range_list'){
			navigation_expand_range_list('down',210);
		}else if(template == 'scroll'){
			navigation_expand_scroll('down',210);
		}else{
			navigation_expand('down',210);

		}
		
	}else{
		
		Event.element(event).src = 'assets/templates/site/img/navigation/arrow.gif';
		if(template == 'range'){
			navigation_expand_range('up',210);
		}else if(template == 'range_list'){
			navigation_expand_range_list('up',210);
		}else if(template == 'scroll'){
			navigation_expand_scroll('up',210);
		}else{
			navigation_expand('up',210);

		}
		
	}

}


function buttonClick(event){
	//alert(Event.element(event).id);
	var  id = Event.element(event).id;
	switch(id){
		case 'sub_1':
			page = 'electric_cars.html';
		break;
		
		case 'sub_2':
			page = 'electric_bikes.html';		
		break;
		
		case 'sub_3':
			page = 'commercial.html';		
		break;
		
	}
	window.location = page;
}


function eventChecker (){
	Event.observe('arrow_1', 'click', arrowClick);
 	Event.observe('arrow_2', 'click', arrowClick);
 	Event.observe('arrow_3', 'click', arrowClick);
 	
 	Event.observe('sub_1','click',buttonClick);
 	Event.observe('sub_2','click',buttonClick);
 	Event.observe('sub_3','click',buttonClick);
}


function resize(){
	/*
		called when document is resized
	*/
	window.location.href=window.location.href;
}

function scrollLoad(){
/*
	used when scroll pages are loaded to get the height of the content block
	and the positions the footer and the offers and the news below the content
*/
	//alert(Prototype.Browser.IE);
	var content_height = $('content_scroll').getHeight() + 60;
	var news_height =  $('news_scroll').getHeight();
	var offers_height = $('offers_scroll').getHeight();
	//var under_content_y = $('content_scroll').getStyle('top');
	var news_y = content_height + 'px';
	var offers_y = content_height + news_height + 5 + 'px';
	var footer_y = content_height + news_height + offers_height + 4 + 'px';
	var under_content_height = '-' + (content_height + 90) + 'px';
	var under_news_y = offers_y;
	if(Prototype.Browser.IE){
		news_y = $('content_scroll').getHeight()-120;
		under_news_y = $('content_scroll').getHeight()-330;
		offers_y = $('content_scroll').getHeight()-292;
		footer_y = offers_y + 83;
		
	}
	
	$('news_scroll').absolutize();
	$('news_scroll').setStyle({
 		top: news_y
	});
	$('news_scroll').relativize();
	
	$('offers_scroll').absolutize();
	$('offers_scroll').setStyle({
 		top: offers_y
	});
	$('offers_scroll').relativize();
	
		
	$('footer_scroll').absolutize();
	$('footer_scroll').setStyle({
 		top: footer_y
	});
	$('footer_scroll').relativize();
	
	$('under_news_scroll').absolutize();
	$('under_news_scroll').setStyle({
 		top: under_news_y
	});
	$('under_news_scroll').relativize();
	
	$('under_content').absolutize();
	$('under_content').setStyle({
		top: '62px'
	});
	$('under_content').relativize();
	$('under_content').setStyle({
		top: under_content_height
	});	
}

function nothing(){

}


/*
Taken code
*/

function bookmark() {
	 title = 'NICE Car Company ::' + page_title; 


 	url = page_url = 'http://www.nicecarcompany.co.uk' + page_url;
    // user agent sniffing is bad in general, but this is one of the times 
    // when it's really necessary
    var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from a web server, not directly from a local 
        // file system, otherwise, you will get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
      alert('You need to press CTRL + B to bookmark our site.');
    } else if(window.opera) {
      void(0); // do nothing here (Opera 7+)
    } else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
      alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }
  }
  
var configurator_rgb = 'dc540f';

function rgb_change(rgb_value){
	//alert(rgb);
	configurator_rgb = rgb_value;
}

function getRgb(){
	return configurator_rgb;
}

function saved_change(saved_value){
	//alert(saved_value);
	configurator_saved = saved_value;
}

function getSaved(){
	//configurator_saved = 'no';
	return configurator_saved;

	
}

function setSaved(){
	configurator_saved = 'no';
}

function configurator_text(){
	// alert(title);
	configuratorLoad();
}

function configuratorLoad(){
	/*
	sets the result for the configurator when loaded
	*/
	var code_out = '<table width="288" cellpadding="0" cellspacing="0">';
		code_out += '<tr><td class="top_left" width="10" height="13"></td><td class="top_line" colspan="2" width="267" height="13"></td><td class="top_right" width="11" height="13"></td></tr>';

		code_out += '<tr>';
		code_out +=	'	<td class="side_left" width="10"></td>';
		code_out +=	'	<td class="table_left" width="200"><h4>Your Mega city</h4></td>';
		code_out +=	'	<td class="table_right" width="67"> &nbsp;</td>';
		code_out +=	'	<td class="side_right" width="10"></td>';
		code_out +='</tr>';


	var total = 0.00;
	var configuratorForm = $('configurator').getElements();
	for(i in configuratorForm){
		if(configuratorForm[i]['checked'] == true && configuratorForm[i]['name'] != 'colour'){
			code_out += '<tr>';
			code_out +=	'	<td class="side_left" width="10"></td>';
			code_out +=	'	<td class="table_left" width="200">' + configuratorForm[i]['title'] +'</td>';
			code_out +=	'	<td class="table_right" width="67"><strong>£' + parseInt(configuratorForm[i]['value']) + '</strong></td>';
			code_out +=	'	<td class="side_right" width="10"></td>';
			code_out +='</tr>';


			/*code_out += '<tr class="table_row"><td width="75%">';

			code_out += '<div id="config_results_block_left"><p>';
			code_out += configuratorForm[i]['title'];
			code_out += '</p></div></td>';

			code_out += '<td width="25%"><div id="config_results_block_right"><strong>£';
			code_out += parseInt(configuratorForm[i]['value']);
			code_out += '</strong></div>';

			code_out += '</td></tr>';*/
			
			total +=parseFloat(configuratorForm[i]['value']);
		}
	}

	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="table_left" width="200"><strong> </strong></td>';
	code_out +=	'	<td class="table_right" width="67"><strong> </strong></td>';
	code_out +=	'	<td class="side_right" width="10"></td>';
	code_out +='</tr>';

	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="table_left" width="200"><strong>Total(ROTR)</strong></td>';
	code_out +=	'	<td class="table_right" width="67"><strong>£' + total + '</strong></td>';
	code_out +=	'	<td class="side_right" width="10"></td>';
	code_out +='</tr>';
	
	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="button" colspan="2" width="267" align="center"><a href="javascript:saved_change(\'yes\');"><img src="assets/templates/site/img/configurator_result/print_btn.gif" alt="contact for order" title="contact for order" border="0" /></a>&nbsp;<a href="contact_us.html"><img src="assets/templates/site/img/configurator_result/contact_btn.gif" alt="contact for order" title="contact for order" border="0" /></a><br/><sub>pop ups must be enabled for print to work</sub></td>';
	code_out +=	'	<td class="side_right" width="10"></td>';
	code_out +='</tr>';

	code_out += '<tr><td class="bottom_left" width="10" height="20"></td> <td class="bottom_line" colspan="2" width="267" height="20"></td><td class="bottom_right" width="11" height="20"></td></tr></table>';
	//alert(configuratorForm[1]['checked']);
	//alert(total);	
	$('configurator_result').update(code_out);
}


var image_string = '';

function printPause(rnd_string){
	image_string = rnd_string;
	setTimeout("printConfigurator()", 2000);
}

function printConfigurator(){	
	var code_out = '<html><head><link rel="stylesheet" type="text/css" href="assets/templates/site/print.css" /></head><body onload="print();">';
	    code_out += '<center>';
		code_out += '<img src="assets/flash/BitmapExporter_Tempfiles/' + image_string + '.jpg" /><br/>';
	    code_out += '<table width="288" cellpadding="0" cellspacing="0" class="print_table">';
		code_out += '<tr><td class="top_left" width="10" height="13"></td><td class="top_line" colspan="2" width="267" height="13"></td><td class="top_right" width="11" height="13"></td></tr>';

		code_out += '<tr>';
		code_out +=	'	<td class="side_left" width="10"></td>';
		code_out +=	'	<td class="table_left" width="200"><h4>Your Mega city</h4></td>';
		code_out +=	'	<td class="table_right" width="67"> &nbsp;</td>';
		code_out +=	'	<td class="side_right" width="10"></td>';
		code_out +='</tr>';


	var total = 0.00;
	var configuratorForm = $('configurator').getElements();
	for(i in configuratorForm){
		if(configuratorForm[i]['checked'] == true && configuratorForm[i]['name'] != 'colour'){
			code_out += '<tr>';
			code_out +=	'	<td class="side_left" width="10"></td>';
			code_out +=	'	<td class="table_left" width="200">' + configuratorForm[i]['title'] +'</td>';
			code_out +=	'	<td class="table_right" width="67"><strong>£' + parseInt(configuratorForm[i]['value']) + '</strong></td>';
			code_out +=	'	<td class="side_right" width="10"></td>';
			code_out +='</tr>';
			
			total +=parseFloat(configuratorForm[i]['value']);
		}
	}

	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="table_left" width="200"><strong> </strong></td>';
	code_out +=	'	<td class="table_right" width="67"><strong> </strong></td>';
	code_out +=	'	<td class="side_right" width="10"></td>';
	code_out +='</tr>';

	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="table_left" width="200"><strong>Total(ROTR)</strong></td>';
	code_out +=	'	<td class="table_right" width="67"><strong>£' + total + '</strong></td>';
	code_out +=	'	<td class="side_right" width="10"></td>';
	code_out += '</tr>';
	code_out += '<tr>';
	code_out +=	'	<td class="side_left" width="10"></td>';
	code_out +=	'	<td class="table_left" width="267" colspan="2">';
	code_out += '	<br/><strong>NICE Car Company Ltd</strong>,<br />';
	code_out += '	332 Ladbroke Grove, <br />';
	code_out += '	London W10 5AH <br />';
	code_out += '	<br />';
	code_out += '	<strong>Call us:</strong>	0845 642 3227   <br />';
	code_out += '	<strong>Email us:</strong>	theteam@nicecarcompany.co.uk ';
	code_out += '   </td>';

	code_out +=	'	<td class="side_right" width="10"></td>';

	code_out += '</tr>';
	code_out += '</table>';
	code_out += '</center>';

	//var DocumentContainer = document.getElementById('configurator_result');
    var WindowObject = window.open('', "print", "width=500,height=500,top=0,left=0,toolbars=no,scrollbars=yes,status=no,resizable=no");
     // var img = processCookie ('unique_id', 'read', 'unique_id',"");
    //alert(img_cookie);
    //alert(document.cookie);
    //code_out += DocumentContainer.innerHTML;
    //alert(code);
    code_out += '</body></html>';
    WindowObject.document.writeln(code_out);
    WindowObject.document.close();
    WindowObject.focus();
    // WindowObject.location ='assets/flash/removefiles.php?id=' + image_string;
    //WindowObject.close();
    
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


