function switch_tabs(tab){
	var tabs = document.getElementById('tabs').getElementsByTagName('li').length;
	//switch off all tabs and content
	for(i=0; i<tabs; i++){
		document.getElementById('tab' + (i+1)).className = '';
		document.getElementById('tab' + (i+1)+'_content').style.display = 'none';
	}
	//switch the selected tab and content
	document.getElementById(tab).className = 'selected';
	document.getElementById(tab+'_content').style.display = 'block';
};
function showDiv(content){
	var news = document.getElementById('content').getElementsByTagName('li').length;
	//switch off all tabs and content
	for(i=0; i<news; i++){
		document.getElementById('content' + (i+1)).className = '';
		document.getElementById('content' + (i+1)+'_content').style.display = 'none';
	}
	//switch the selected tab and content
	document.getElementById(content).className = 'selected';
	document.getElementById(content+'_content').style.display = 'block';
};

// ################
// #### NEWS TEASER
// ################
function reset_news_teaser() {
  new Effect.Fade('news_teaser',{duration: .5, afterFinish:function(){rotate_news();}});
}

function rotate_news() {

  var n = $('rank').value;
  var params = "rank="+n;
  var go_url = "/news_and_events/get_next.php";

  new Ajax.Request(go_url, {
        method:'post', 
        parameters: params, 
        onSuccess: function(obj){show_news(obj, 'success');}, 
        onFailure:function(obj){show_news(obj, 'fail');}
      });
}

function show_news(obj, s) {
   if (s == 'success') {
    $('news_teaser').innerHTML = obj.responseText;
    Effect.Appear('news_teaser', {duration: .5});
   } else {
      //alert('error');
   }
}

/* NAVIGATION FUNCTIONS */
function show_subnav(obj) {
  var nav_list = $$('ul.nav_list');
  nav_list.each(function(item){item.hide();});

  var nav_img = $$('img.nav_image');
  //alert(nav_img);
  nav_img.each(function(item){
    var rel = item.readAttribute('rel');
    var img_src = item.src;
    if(item == $('nav_img_'+obj) && item.src.search(/over/i) <0) {
      var tmp = item.src;
      item.src=rel;
      item.writeAttribute('rel', tmp);
    } else if(item != $('nav_img_'+obj) && item.src.search(/over/i) >0) {
        if(item.src.search(/over/i) > 0) {
          var tmp = item.src;
          item.src=rel;
          item.writeAttribute('rel', tmp);
        }
    }
  });;

  var show_nav = $$('ul.nav_'+obj);
  show_nav.each(function(item){item.show();});
  
}

/*
########################
### LISTINGS FUNCTIONS
########################
*/

function switch_listings_filter(obj_id) {
	if($(obj_id+"_container").style.display == "none") {
		$(obj_id+'_button').src = "images/minus_icon.png";
		new Effect.SlideDown(obj_id+"_container", {duration:0.1});
	} else {
		$(obj_id+'_button').src = "images/plus_icon.png";
		new Effect.SlideUp(obj_id+"_container", {duration:0.2});
	}
}

function listings_filter(category, value) {
	// hide all rows
	var show_rows = $$('tr.model_listing');
	show_rows.each(function(row) {
		$(row).style.display = 'none';
	});
	
	// show applicable rows
	var show_rows = $$('tr.'+category+'--'+value);
	$('listings_count').value=show_rows.length;
	show_rows.each(function(row) {
		$(row).style.display = '';
	});
}

var closeout_status = "up";
var animate_banner = 1;
var animate_overlay = 1;
function animate_closeout_banner() {
	if(closeout_status == "up") {
		// hide the banner
		var banner_up = new Effect.SlideUp('closeout_banner', {
			duration: 0.2,
			beforeStart:function(){
				if(animate_banner ==1){
					animate_banner = 2;
				} else {
					banner_up.cancel();
				}
			},
			afterFinish:function(){
				animate_closeout_overlay();
			}
		});
	} else {
		// slide up overlay
		animate_closeout_overlay();
	}
}

	function animate_closeout_overlay() {
		if(closeout_status == "up") {
			var overlay_down = new Effect.SlideDown('closeout_overlay', {
				beforeStart:function(){
					if(animate_overlay ==1){
						animate_overlay = 2;
					} else {
						overlay_down.cancel();
					}
				},
				afterFinish:function(){
					animate_overlay = 1;
					animate_banner = 1;
					closeout_status = "down";
				}
			});
		} else {
			// slide overlay up and show banner
			var overlay_up = new Effect.SlideUp('closeout_overlay', {
				beforeStart:function(){
					if(animate_overlay ==1){
						animate_overlay = 2;
					} else {
						overlay_up.cancel();
					}
				},

				afterFinish:function(){
					// slide banner down
					var banner_down = new Effect.SlideDown('closeout_banner', {
						duration: 0.2,
						beforeStart:function(){
							if(animate_banner ==1){
								animate_banner = 2;
							} else {
								banner_down.cancel();
							}
						},
						afterFinish:function(){
							animate_overlay = 1;
							animate_banner = 1;
							closeout_status = "up";
						}
					});
				}
			});
		}
	}

// animation for 4.9% financing ad

function slide_svc_div(div, img){
	
	if(document.getElementById(div).style.display == 'none'){
		closeout_status = "up";
	} else {
		closeout_status = "down";
	}
	
	if(closeout_status == "up") {
		var div_down = new Effect.SlideDown(div, {
						duration: 1,
						afterFinish:function(){
							img.src = "/images/buttons/serviceDetailsBtnUp.png";
							this_div.down = true;
							
						}
					});
	} else {
			var div_up = new Effect.SlideUp(div, {
						duration: 1,
						afterFinish:function(){
							img.src = "/images/buttons/serviceDetailsBtn.png";
						//	closeout_status = "up";
						}
					});
	}
}
	





/*
########################
### END LISTINGS FUNCTIONS
########################
*/




