// JavaScript Document

//$.noConflict();

$(document).ready(function() {
						   $('html').addClass('js');
$(window).bind("load",function(){ 
$('div.js-hide').removeClass('js-hide');

});
//$('html').attr('xmlns:fb', 'http://www.facebook.com/2008/fbml');
$(function() {
    $('#advert').cycle({
        fx:     'turnDown',
        speed:  'slow',
        timeout: 8000,
        pager:  '#nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#nav li:eq(' + (idx) + ') a';
        }
    });
});








$(function() {
    $('.advertOffer').cycle({
        fx:     'turnDown',
        speed:  'slow',
        timeout: 10000,
        pager:  '.nav2',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '.nav2 li:eq(' + (idx) + ') a';
        }
    });
});


						   $('html').removeClass('js');
  $("a").filter(function() {
    return this.hostname && this.hostname !== location.hostname;
}).addClass('external').attr("target", "_blank");

$('a.addthis_button').removeClass('external');
$('a.noExternal').removeClass('external');
$("a[href$='.pdf']").addClass("pdf").attr("target", "_blank");
//$(function()
//{
//	$('.date-pick').datePicker({startDate:'01/01/1990'});
//});
 
$('#pause2').toggle(function() { 

                $('#s2,#s3,#s4,#s5').cycle('pause'); 
                $(this).attr({ src: "/images/Play-Button-27x27.png"}); 
				return false;

                }, function() { 

                $('#s2,#s3,#s4,#s5').cycle('resume', true); 
                $(this).attr({ src: "/images/Pause-Button-27x27.png"}); 
				return false;
        });


var max = 0;
    $(".enquiryForm label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();    
    });
    $(".enquiryForm label").width(max);


$(function() {  
// OPACITY OF BUTTON SET TO 50%  
$(".footerLogos img, .footerLogosHP img").css("opacity","1.0");  
 // ON MOUSE OVER  
 $(".footerLogos img, .footerLogosHP img").hover(function () {  
// SET OPACITY TO 100%  
 $(this).stop().animate({  
 opacity: 0.5  
 }, "slow");  
 },  
 // ON MOUSE OUT  
 function () {  
 // SET OPACITY BACK TO 50%  
 $(this).stop().animate({  
 opacity: 1.0  
 }, "slow");  
 });  
 }); 


});


 $(function() {
        $('#dealerAdvertRotator').cycle({ 
    fx:      'blindX', 
    speed:    300, 
    timeout:  5000 
});
    });

$(function() {

	$('#s2,#s3,#s4,#s5').cycle({
    fx:     'fade',
    speed:  'fast',
	timeout: 3000,
    next:   '#next2',
    prev:   '#prev2'
});
	});




 $(function() {
        $('.UCofferRota').cycle({ 
    fx:      'blindX', 
    speed:    300, 
    timeout:  5000 
});
    });

 $(function() {
        $('.newCarHubRota').cycle({ 
    fx:      'fade', 
    speed:    300, 
    timeout:  5000 
});
    });

$(function(){
		

		//	$("input").attr("autocomplete","off");
			
			$('input[title], textarea[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
			



//$.viewMap = {
//    //'0' : $([]),
//    'newsales' : $('#newsales'),
//    'usedsales' : $('#usedsales'),
//    'service' : $('#service'),
//	'parts' : $('#parts')
//  };
//  $('#usedsales, #service, #parts').hide();
// 
//  $('.TextBox').change(function() {
//    // hide all
//    $.each($.viewMap, function() { $(this).hide(); });
//    // show current
//    $.viewMap[$(this).val()].show();
//  });








		  


		});



function CountDown(TargetDate,StartDate,id)
{
document.write("<span id='" + id + "' class=info></span>");

var dthen = new Date(TargetDate);
var dnow = new Date(StartDate);
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs,id);
}

function CountBack(secs,id)
{
  if (secs < 0) {
    document.getElementById(id).innerHTML = "Vehicle no longer for sale";
    return;
  }
  
  
  DisplayFormat = "Must Sell - Offer Ending Soon <span class=\"countdown\"><span class=\"countdownBdr\" %%D%% d</span> <span class=\"countdownBdr\"%%H%% h</span> <span class=\"countdownBdr\"%%M%% m</span> <span class=\"countdownBdr\"%%S%% s</span>";
  
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById(id).innerHTML = DisplayStr;
  
  setTimeout("CountBack(" + (secs-1) + ",'" + id + "')", 990);
}
function calcage(secs, num1, num2)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function testIsValidObject(objToTest)
    {
    if (objToTest == null || objToTest == undefined)
       {
       return false;
       }

    return true;
}

