$(function(){
// Click-tracking functions
	var thePage = $('body').attr('id');
	var theImage = '';
	var theList = [];
	var laundryImg = '<img src="http://ad.doubleclick.net/activity;src=1032867;type=mayla09;cat=';
	var refrigerationImg = '<img src="http://ad.doubleclick.net/activity;src=1032867;type=mayfri09;cat=';
	var dishwashersImg = '<img src="http://ad.doubleclick.net/activity;src=1032867;type=mydish09;cat=';
	var cookingImg = '<img src="http://ad.doubleclick.net/activity;src=1032867;type=mycook09;cat='
	var imageEnd = '?" alt="" width="1" height="1" border="0" class="doubleclick">';
	var laundryList = [
	    'lanhp09;ord=1;num=',
	    'persh01;ord=1;num=',
	    'brov01;ord=1;num=',
	    'epicshop;ord=1;num=',
	    'centshop;ord=1;num='
	];
	var refrigerationList = [
	    'frhp09;ord=1;num=',
	    'fredoor1;ord=1;num=',
	    'sidex201;ord=1;num=',
	    'bofreez;ord=1;num=',
	    'topfreez;ord=1;num='
	];
	var dishwashersList = [
	    'dishhp09;ord=1;num=',
	    'dishdraw;ord=1;num=',
	    'steamdis;ord=1;num=',
	    'hdexdish;ord=1;num=',
	    'talltub1;ord=1;num='
	];
	var cookingList = [
	    'cookhp09;ord=1;num=',
	    'rangcook;ord=1;num=',
	    'micrcook;ord=1;num=',
	    'builtovn;ord=1;num=',
	    'cooktop;ord=1;num='
	];

    if (thePage == 'laundry')
    {
        var theImage = laundryImg;
        var theList = laundryList;
    }
    if (thePage == 'refrigeration')
    {
        var theImage = refrigerationImg;
        var theList = refrigerationList;
    }
    if (thePage == 'dishwashers')
    {
        var theImage = dishwashersImg;
        var theList = dishwashersList;
    }
	if (thePage == 'cooking'){
        var theImage = cookingImg;
        var theList = cookingList;
    }
    
    $.each(theList, function(i){
        if (i < 1)
        {
    		var jk = new Date();
    		var kk = jk.getTime();
        	$('body').append(theImage + theList[i] + kk + imageEnd);
        }
        else
        {
            $('#product-' + i + ' .shop-now').click(function(){
                var mk = new Date();
                var ok = mk.getTime();
                var goThere = $(this).attr('href');
                $(this).append(theImage + theList[i] + ok + imageEnd);
                $('.doubleclick').hide().show().animate({opacity: 1.0}, 250).hide().show();
                window.location.assign(goThere);
                return false;
            });
        }
    });
    $('#maytagmonth-promo-form, .download-rebate-link a').click(function(){
        var rebatePrefix = '<img src="http://ad.doubleclick.net/activity;src=1032867;type=mayhd09;cat=mayreb09;ord=1;num=';
        var pk = new Date();
        var qk = pk.getTime();
        var goThere = $(this).attr('href');
        $(this).append(rebatePrefix + qk + imageEnd);
        $('.doubleclick').hide().show().animate({opacity: 1.0}, 250).hide().show();
        window.open(goThere, '_blank');
        return false;
    });
    $(function() {
        var itim = new Date();
        var timbits = itim.getTime();
	    $('body#home').append('<img src="http://ad.doubleclick.net/activity;src=1032867;type=mayhd09;cat=mayhdlp;ord=1;num=' + timbits + imageEnd);
    });
    
// Demo pop-ups
	$('.view-demo').click(function(){
	    var demoURL = $(this).attr('href');
	    var demoPath = /[^\s]+(?=\.html)/;
	    var demoFile = demoURL.replace(demoPath,'');
	    if (demoFile == '.html') { window.open(demoURL, '_blank', 'height=559,width=666'); }
	    else { window.open(demoURL, '_blank', 'height=369,width=573,resizeable=1,scrollbars=1'); }
        return false;
	});
	

// Demo sxs pop-ups
	$('.view-demo-sxs').click(function(){
	    var demoURL = $(this).attr('href');
	    var demoPath = /[^\s]+(?=\.html)/;
	    var demoFile = demoURL.replace(demoPath,'');
	    if (demoFile == '.html') { window.open(demoURL, '_blank', 'height=559,width=666'); }
	    else { window.open(demoURL, '_blank', 'height=570,width=765,resizeable=1,scrollbars=1'); }
        return false;
	});
	
// Demo pop-ups2
	$('.view-demo2').click(function(){
	    var demoURL = $(this).attr('href');
	    var demoPath = /[^\s]+(?=\.html)/;
	    var demoFile = demoURL.replace(demoPath,'');
	    if (demoFile == '.html') { window.open(demoURL, '_blank', 'height=612,width=816'); }
	    else { window.open(demoURL, '_blank', 'height=612,width=816,resizeable=1,scrollbars=1'); }
        return false;
	});
	

// Demo sxs pop-ups2
	$('.view-demo-sxs2').click(function(){
	    var demoURL = $(this).attr('href');
	    var demoPath = /[^\s]+(?=\.html)/;
	    var demoFile = demoURL.replace(demoPath,'');
	    if (demoFile == '.html') { window.open(demoURL, '_blank', 'height=612,width=816'); }
	    else { window.open(demoURL, '_blank', 'height=612,width=816,resizeable=1,scrollbars=1'); }
        return false;
	});

// PDF download pop-up
	$('.pdf-download, .download-rebate-link a, #maytagmonth-promo-form').attr('target','_blank');
	
	
// Features box showy-hidey thing
	$('#show-features').show().click(function(){
	    $('#features-box').fadeIn();
	    return false;
	});
	$('#features-box #close').click(function(){
	    $('#features-box').fadeOut();
	    return false;
	});
	
	
// Promotions handlers
	var promoID = $('.promo').attr('id');
	if (promoID != 'promo-none')
	{
        $('.promo #homedepot-promo').hover(
            function(){$(this).addClass('rollover');},
            function(){$(this).removeClass('rollover');}
        );
	}
	$('.mimm-promo-home li').hover(
	    function(){$(this).addClass('mimmRollover');},
	    function(){$(this).removeClass('mimmRollover');}
	);
	$('.mimm-promo-other li').hover(
	    function(){$(this).addClass('mimmRollover');},
	    function(){$(this).removeClass('mimmRollover');}
	);

});