var domain = window.location.href.split("/")[2];

$(document).ready(function(){
	$(document).bind("session:dealer", setDealerSessionItems);
	$('#footerGrey').vwFooter();
	
	$('.articleListItem').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	$('li.bestOfWeb').click(function(){
	    var link = $(this).find('a').attr("href");
	    window.open(link);
	    return false;
    });
	
	if($('#specialeditions-topleft').height() < $('#specialeditions-topright').height()){
		$('#specialeditions-topleft').css('height', $('#specialeditions-topright').css('height'));
		$('#specialeditions-topleft').find('.content_bl').css('position', 'absolute');
		$('#specialeditions-topleft').find('.content_bl').css('top',  ($('#specialeditions-topright').height() - 6) + "px");
		if(jQuery.browser.msie){
		    $('#specialeditions-topleft').css('height',$('#specialeditions-topright').height() + "px");
		}
	}else{
		$('#specialeditions-topright').css('height', $('#specialeditions-topleft').css('height'));
		$('#specialeditions-topright').find('.content_bl').css('position', 'absolute');
		$('#specialeditions-topright').find('.content_bl').css('top',  ($('#specialeditions-topleft').height() - 6) + "px");
		if(jQuery.browser.msie){
		    $('#specialeditions-topright').css('height',$('#specialeditions-topleft').height() + "px");
		}
	}
	
	$('.article-read-more').click(function(e){
		e.preventDefault();
		
		$(this).parent().parent().find('.brief').addClass('hidden');
		$(this).parent().parent().find('.full').removeClass('hidden');
	});
	$('.article-read-less').click(function(e){
		e.preventDefault();
		$(this).parent().parent().parent().find('.brief').removeClass('hidden');
		$(this).parent().parent().parent().find('.full').addClass('hidden');
	});
	
	$('.promos').find('a img').hover(function(e){
		$(this).css('top', '-95px');
	},function(e){
		$(this).css('top', '10px');
	});
	
	$('.sendEmail').click(function(e){
		e.preventDefault();
		var url = "http://"+domain+"/specialeditions/beetleblush/en/us/"
		var message = "I thought you might like to see this on vw.com.\n";
		message += url+"\n";
		message += "If I'm mistaken, please disregard.\n";
		message += "If not, check it out. And pass it on.\n";
		message += "Then thank me for keeping you in the loop by sending me an interesting VW link of your own.\n";
		setShowEmail(message);
	});
	$('a.shareLink').hover( function () {
		$('#shareContainer').show();
		$('#emailSend').hide();
		}, function () {

	});
	$('#shareContainer').hover( function () {

		}, function () {
		$('#shareContainer').hide();
	});
	
	//TODO
	$('.articleListItem a').click(function(e){
		e.preventDefault();
	})
	
	
	$('.blush-downloadspecs').click(function(e){
		$.ajax({
            type: 'GET',
            url: '/global/js/omniture/s_code.js',
            dataType: 'html',
            success: function(html) {
				s.pageName="models:new beetle convertible blush:download";
			 	s.server=vwServerName;
			 	s.domain=vwDomain;
			 	s.channel="models";
			 	s.events="event16";
                var s_code=s.t();if(s_code)document.write(s_code);
            },
            error: function(e) {
	            //alert(e);
            }
        });
	});
	
	try{
		if(dealersession){ //used if not cached
			if(dealersession.isDealerSession == true){
				setDealerSessionitems({}, dealersession);
			}
		}
	}catch(e){
	}
});

function setShowEmail(msg){
	//util.getNode('emailer').replaceEmailMessage(msg);
	showEmail();
	return false;
}
function getDomain(){
	return domain;
}

function setDealerSessionItems(e, obj){
	if(obj.isDealerSession){ 
		$(".finddealer").removeClass('finddealer').addClass('contactdealer');
		$('.contactdealer').text('Contact Dealer');
		$(".contactdealer").attr({href:"http://"+dealersession.dealerDomain+"/ContactUsForm/"});
		$('.getquote').attr({href:"http://"+dealersession.dealerDomain+"/QuickQuoteForm/"});
		$('.testdrive').attr({href:"http://"+dealersession.dealerDomain+"/ContactUsForm/"});
	}
}