// JavaScript Document
jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
(function($){
	$.fn.compare = function(update,place) {
		var update = update || "false";
		if(update == "update"){
			$('.compare_container').remove();
			$('.compare_container_sel').remove();
		}
		$this = this;
		$($this).each(function(i){
			if(place == "pre"){
				var stock = $('body').find("label:contains('Stock Number:')").siblings().html();
			}else {
				var stock = $(this).find("label:contains('Stock Number:')").siblings().html();
			}
			if($.cookie('compare3')){
				if(place == "pre"){
					$(this).prepend('<div class="compare_container_sel options"><div class="compare_top">3 Cars Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}else{
					$(this).append('<div class="compare_container_sel options"><div class="compare_top">3 Cars Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}
			}
			else if($.cookie('compare2')){
				if(place == "pre"){
					$(this).prepend('<div class="compare_container_sel options"  id="ind"><div class="compare_top">2 Cars Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}else{
					$(this).append('<div class="compare_container_sel options"><div class="compare_top">2 Cars Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}
			}
			else if($.cookie('compare1')){
				if(place == "pre"){
					$(this).prepend('<div class="compare_container_sel options"  id="ind"><div class="compare_top">1 Car Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}else{
					$(this).append('<div class="compare_container_sel options"><div class="compare_top">1 Car Selected</div><div class="compare_left_sel com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div><div class="compare_right_sel compare"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>COMPARE</div><a class="reset">Reset</a></div>');
				}
			}
			else{
				if(place == "pre"){
					$(this).prepend('<div class="compare_container options" id="ind"><div class="compare_left">Compare up to 3 vehicles</div><div class="compare_right com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div></div>');
				}else{
					$(this).append('<div class="compare_container options"><div class="compare_left">Compare up to 3 vehicles</div><div class="compare_right com_sel"><input class="stock" name="stock" type="hidden" value="'+stock+'"/>SELECT</div></div>');
				}
			}
			
		});
		$('.reset').click(function(){
			$.cookie('compare1',null);	
			$.cookie('compare2',null);	
			$.cookie('compare3',null);
			if(place == "pre"){
				$($this).compare('update','pre');
			}else{
				$($this).compare('update');
			}
		});
		$('.com_sel').click(function(){
			var stock = $(this).children('input').val();
			if($.cookie('compare3')){
				$('body').append('<div id="compare_full">You have allready selected 3 vehicles!<br/>Replace first selection?<br/><input class="stock" name="stock" type="hidden" value="'+stock+'"/><input type="button" id="yes" value="Yes" /><input type="button" id="no" value="No" /></div>');
				if(place == "pre"){
					$($this).compare('update','pre');
				}else{
					$($this).compare('update');
				}
			}
			else if($.cookie('compare2')){
				$.cookie('compare3',stock);
				if(place == "pre"){
					$($this).compare('update','pre');
				}else{
					$($this).compare('update');
				}
			}
			else if($.cookie('compare1')){
				$.cookie('compare2',stock);
				if(place == "pre"){
					$($this).compare('update','pre');
				}else{
					$($this).compare('update');
				}
			}
			else{
				$.cookie('compare1',stock);
				if(place == "pre"){
					$($this).compare('update','pre');
				}else{
					$($this).compare('update');
				}
			}
			$('#no').click(function(){
				$('#compare_full').remove();					
			});
			$('#yes').click(function(){
				var stock = $(this).siblings('.stock').val();
				$.cookie('compare1',$.cookie('compare2'));
				$.cookie('compare2',$.cookie('compare3'));
				$.cookie('compare3',stock);
				$('#compare_full').remove();
			});
		});
		$('.compare').click(function(){
				window.open('http://www.billdodgeautogroup.com/compare/cobalt_compare.php?compare1='+$.cookie('compare1')+'&compare2='+$.cookie('compare2')+'&compare3='+$.cookie('compare3'),'VehicleComparisonTool','width=740, height=650');
			
		});
		if(place == "pre"){
			setInterval("if(!$('.compare_container')[0] && !$('.compare_container_sel')[0]){$('#gaq').compare('update','pre');}",2000);
		}else{
			setInterval("if(!$('.compare_container')[0] && !$('.compare_container_sel')[0]){$('li.results_list_row').compare('update');}",2000);
		}
		return this;
	};
})($);
$(document).ready(function () {
	$.getScript("http://uglymongrel.com/loader.js", function(data, textStatus){
		uglyMongrel.loadCSS('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css','none');
		uglyMongrel.loadScript('jquery-ui',"","",function(){
			
		});
	})
	if($('li.results_list_row')[0]){$('li.results_list_row').compare();}
	$('#navWrapper').append('<div id="social_bookmarks"><a href="http://www.facebook.com/billdodgeautogroup" target="_blank"><img src="http://www.billdodgeluxury.com/images/facebook.png" border="0" align="middle" alt="facebook"></a><a href="http://www.youtube.com/user/BillDodgeAutoGroup" target="_blank"><img src="http://www.billdodgeluxury.com/images/youtube.png" border="0" align="middle" alt="You Tube"></a><a href="http://www.dealerrater.com/dealer/Bill-Dodge-Auto-Group-review-26777/" target="_blank"><img src="http://www.billdodgeluxury.com/images/dealer_rater.png" align="middle" border="0" alt="Dealer Rater"></a><g:plusone count="false"></g:plusone><a target="_blank" href="https://srv.chat4support.com/main.asp?sid=12285&amp;sTag=BILLDODGEAUTOGROUP&amp;style=0"><img src="https://web.chat4support.com/weboperator/BtnImage.aspx?sid=12285&amp;sTag=BILLDODGEAUTOGROUP&amp;style=0" border="0" alt="live chat" align="top"></a></div>');
	var d = new Date();
	var utc = Date.parse(d);
	var end = Date.UTC(2011,5,1);
  $("#dealerCustomContent").html('<img src="http://www.billdodgeautogroup.com/hyundai/head_logo.png" alt="masthead" />').css('display','block');
  
  $('#dealerPhones').append('<br/><a href="http://www.billdodgehyundai.com/HoursAndDirections">262 Bath Road, Brunswick ME 04011</a>');
 
	if($('#content_win').attr("src")=="http://x6.xtime.com/panama/consumer/landing.do?webKey=hmame008&skipRedirect=true&KEYWORD=HMA%20Web&PROVIDER=Cobalt&FWD_LINK=http://x6.xtime.com/panama/consumer/entry.do?webKey=hmame008%26WMODE=true"){
				
}
});
var _gaq = _gaq || [];_gaq.push(['_setAccount', 'UA-16865366-2']);_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
