var timeout    = 0;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

$(document).ready(function(){ 
	$(document).pngFix(); 
	$(".logo").hover(function(){
			$(this).stop().fadeTo(300, 0.7); // This should set the opacity to 100% on hover
			},function(){
			$(this).stop().fadeTo(200, 1.0); // This should set the opacity back to 60% on mouseout
			});

	
	$("a.more").fadeTo("fast", 1.0);
	$("a.more").hover(function(){
			$(this).stop(true, true);
			$(this).animate( { marginLeft: "5px", opacity: 0.9 }, 200);
		},
		function(){
			$(this).animate( { marginLeft: "0px", opacity: 1.0 }, 200);
		});
	$(".switch_panel a").click(function(){
		$('ul', $(this).parent().parent()).slideToggle("slow");
		$(this).toggleClass("active"); return false;
		});
	$(".switch_panel_trim a").click(function(){
		$('.hide', $(this).parent().parent()).slideToggle("slow");
		$(this).toggleClass("active"); return false;
		});
	$("a.expand").click(function(){
		$('.hide').slideToggle("slow");
		$(this).toggleClass("active"); return false;
		});
	$("a.advanced").click(function(){
		$('.advanced_search').slideToggle("slow");
		$(this).toggleClass("active"); return false;
		});
	$("a.switch").click(function(){
		$('div', $(this).parent().parent()).slideToggle("slow");
		$(this).toggleClass("active"); return false;
		});
	

	
	$('input').checkBox();
	//$('select').selectbox();
	$('.select_small select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 69}); 	
	$('.box_form_value select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 269});
	$('.box_form_home select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 200});
	$('.dotted_form select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 207});
	$('.main_form select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 290});
	$('.form_row .select_day select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 69});
	$('.form_row select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 207});
	$('.main_form .advanced_left select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 137});
	$('.main_form .advanced_right select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 137});
	$('.account .account_bar  select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 137});
	$('select').selectmenu({style:'dropdown', maxHeight: 150, menuWidth: 180});
	$('.clearOnFocus').clearOnFocus();
});

Cufon.replace('h1,h2, .foot h4, #shopby h3, .box_title h3, table.newbrand td.title h3, .results_box_big h3, .results_box_big span, .results_box h3, .results_box span, .results_box_small h3, .results_box_small span, div.price, td a.cbb_search, .dotted_seporator h3, .switch_panel_trim a, table.configure_steps h4, .popup_top h1, .award_panel p, .award_panel strong, .top_lister .top_car div.price_lister strong, table.value_results td, .loans h4');

Cufon('#header label, .box_title h3', {
      textShadow: '#000 0px -1px'
});

Cufon.replace('#subnav li a, #shopby h3, .home_news h3 a, .home_reviews h3 a, .home_advice h3 a, a.news_tab1, a.news_tab2, a.news_tab3, .trade_in_value h2', {
	  textShadow: '#fff 0px 1px',
      hover: true
});

Cufon.replace('.results_box_big h3, .results_box_big span, .results_box h3, .results_box span, .results_box_small h3, .results_box_small span', {
	  textShadow: '#fff 0px 1px'
});
Cufon.replace('.box_title_home h1, .shopby_home .box_title h3', {
	  textShadow: '#036998 0px -1px'
});
Cufon.replace('.box_title_value h3', {
	  textShadow: '#35832d 0px -1px'
});
Cufon.replace(' .award_panel p, .award_panel strong', {
	  textShadow: '#00729b 0px -1px'
});
Cufon.replace('td a.cbb_search', {
	  textShadow: '#1d7614 0px -1px'
});


/*  $(function() {
		$('#slideshow_timeline').cycle({
			speed:  1000,
			timeout: 0,
			pager:  '#nav_tabs',
			pagerAnchorBuilder: function(idx, slide) {
				// return sel string for existing anchor
				return '#nav_tabs li:eq(' + (idx) + ') a';
			}
		});
	});  
  
  
$(function() {
		$('#home_form_switch').cycle({
			speed:  1000,
			timeout: 0,
			pager:  '.box_title_home',
			pagerAnchorBuilder: function(idx, slide) {
				// return sel string for existing anchor
				return '.box_title_home div:eq(' + (idx) + ') a';
			}
		});
	}); 

$(function() {
		$('#featured_switch').cycle({
			speed:  1000,
			timeout: 0,
			pager:  '.featured_pag1',
			pagerAnchorBuilder: function(idx, slide) {
				// return sel string for existing anchor
				return '.featured_pag1 li:eq(' + (idx) + ') a';
			}
		});
	}); 
$(function() {
		$('#featured_switch2').cycle({
			speed:  1000,
			timeout: 0,
			pager:  '.featured_pag2',
			pagerAnchorBuilder: function(idx, slide) {
				// return sel string for existing anchor
				return '.featured_pag2 li:eq(' + (idx) + ') a';
			}
		});
	}); */
(function($) {
	$.fn.clearOnFocus = function() {
		
		function clearOnFocusFocus(event)
		{
			if($(this).val() == $(this).data('clearOnFocus'))
			{
				$(this).val('');
			}
		}
		
		function clearOnFocusBlur(event)
		{
			if($.trim($(this).val()) == '')
			{
				$(this).val($(this).data('clearOnFocus'));
			}
		}
		
		return this.each(function()
			{
				$(this).data('clearOnFocus', $(this).attr('value'));
				
				//	unbind any previous listeners
				$(this).unbind('focus', clearOnFocusFocus);
				$(this).unbind('blur', clearOnFocusBlur);
				
				//	bind listeners to the functions
				$(this).bind('focus', clearOnFocusFocus);
				$(this).bind('blur', clearOnFocusBlur);
			}
		);
	};
})(jQuery);