function shmugFix(){
	$("#pageWrapperTop, #pageWrapperBottom").height(Math.max($(document).height(), $("#pageWrapperBottom").height()));
}

$.attachTrueEffect=function(url){
	try{
		var axel = Math.random();
		var a = axel * 10000000000000;
		$('body').append($('<IFRAME SRC="'+ url + '&random=' + a + '" WIDTH="1" HEIGHT="1" SCROLLING="No" FRAMEBORDER="0" MARGINHEIGHT="0" MARGINWIDTH="0"></IFRAME>'));
		$.log('attachTrueEffect("'+url+'")');
	}catch (e) {
		$.log('ERROR attachTrueEffect:'+e);
	}
};

$.attachAtlas=function(actionId){
	try{
		$('body').append($('<iframe src="http://view.atdmt.com/iaction/'+ actionId + '" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>'));
		$.log('attachAtlas("'+actionId+'")');
	}catch (e) {
		$.log('ERROR attachAtlas:'+e);
	}
};

function initFancybox(){
    $(".fancyboxvideo").each(function(e){
		var iframe_class = $(this).attr('iframe_class');
		if(iframe_class)
		    $(this).fancybox({
			onStart:function(){
		    	    $('#fancybox-outer').addClass(iframe_class);
		    	},
		    	onClosed:function(){
		    	    $('#fancybox-outer').removeClass(iframe_class);
		    	}
		    });
		else
		    $(this).fancybox();
    });
}
function removeXYFromSearchFormSubmittion(){
    $("#sitesearch").submit(function(){
	this.submit();
	return false;
    });
}

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

function trackEvent(g,n,v){
    try{ pageTracker._trackEvent(g,n,v); window.console.log('pageTracker._trackEvent("'+g+'","'+n+'","'+v+'");')} catch(e){}
}

function survey(){
	var SURVEY_COOKIE = 'exit_survey';
	var cookie = $.cookie(SURVEY_COOKIE);
	if(!cookie){
		var date = new Date();
        date.setTime(date.getTime()+(364 * 24*60*60*1000));
        $.cookie(SURVEY_COOKIE, 'true', { path: '/', expires: date });
        var html = '<img id="surveyPrompt" src="/img/survey-popup.gif" alt="" usemap="#surveyMap" /><map name="surveyMap" id="surveyMap"><area shape="rect" coords="20,140,144,162" target="_blank" href="http://www.surveygizmo.com/s3/332558/Zegerid-OTC-Online-Survey" onclick="window.open(this.href,\'survey_window\',\'location=1,status=0,scrollbars=1,width=620\'); $.fancybox.close(); setTimeout(\'window.focus && window.focus();\',500); trackEvent(\'Survey\',\'Take Survey\');return false;"/><area shape="rect" coords="173,142,246,162" href="javascript:(function(){trackEvent(\'Survey\',\'No Thanks\');$.fancybox.close();})();"/></map>';
		$.fancybox(
        		html,
        		{
                	'autoDimensions'	: false,
                	'width'             : 383,
                	'height'            : 202,
        			'transitionIn'		: 'none',
        			'transitionOut'		: 'none',
        			'overlayOpacity'    : 0.4,
        			'showCloseButton'	: false,
					'onStart'			: function(){$('#fancybox-outer').addClass('survey');},
					'onClosed'			: function(){$('#fancybox-outer').removeClass('survey');}
        		}
        	);
        
	}
}

function setCouponTracking(){
    $("[href^='/coupon-interstitial/index.html?couponId=']").click(function(){
	    $.attachTrueEffect('http://ad.adlegend.com/ipixel?spacedesc=1089458_1061349_1x1_1061349_1061349&db_afcr=123&target=_blank&group=Zegerid&event=Get_Coupon_Button&revenue=REVENUE&random=CACHEBUSTER');
    }).fancybox({
    	    width: 660,
    	    height: 400,
    	    type: 'iframe'
    	});;
    $("[href$='couponId=zegeridotc.com/Coupon']").click(function(){$.attachAtlas('cbnzeg_ZegeridCouponInterstitial_5');});
    
    $('#printCoupon').click(function(){
        $.attachAtlas('cbnzeg_CouponsPromotionsPrintYourCouponBUTTON_1');
    });
}

function buyNow() {
       var html = '<div class=\"buyNowContent\"><div class=\"PageTitle\"><img src=\"/img/buyNow/buy-now-header.gif\" alt=\"\" /><p>Zegerid OTC<sup>&reg;</sup> products are available and may be purchased from <br />the online retailers listed below. Click on the logo below to visit that site.</p><div class=\"ClearFloat\"></div></div><p class=\"buyNowNote\">Please be advised that by clicking on the logo below, you will be leaving ZegeridOTC.com and be taken to a website in which the <a href=\"http://www.schering-plough.com/legal/privacy-certified.aspx\" target=\"_blank\">Schering-Plough Privacy Policy</a> will no longer apply. You are solely responsible for your interactions with these websites.</p> <div class=\"calloutsContainer\"> <a onclick="try{trackStore(\'cvs\');}catch(_){}" href=\"http://www.cvs.com/CVSApp/search/search.jsp?searchTerm=zegeridotc\" target=\"_blank\"><img src=\"/img/buyNow/btn-cvs-com.gif\" /></a> <a onclick="try{trackStore(\'drugstore\');}catch(_){}" href=\"http://www.drugstore.com/search/search_results.asp?N=0&Ntx=mode%2Bmatchallpartial&Ntk=All&srchtree=1&Ntt=zegerid&Go.x=0&Go.y=0\" target=\"_blank\"><img src=\"/img/buyNow/btn-drugstore-com.gif\" /></a> <a onclick="try{trackStore(\'samsclub\');}catch(_){}" href=\"http://www.samsclub.com/sams/search/searchResults.jsp?searchTerm=zegerid&searchCategoryId=all\" target=\"_blank\"><img src=\"/img/buyNow/btn-sams-club.gif\" /></a></div></div>';
	$.fancybox(
       		html,
       		{
               	'autoDimensions'	: false,
               	'width'             : 655,
               	'height'            : 261,
       			'transitionIn'		: 'none',
       			'transitionOut'		: 'none',
       			'overlayOpacity'    : 0.4,
       			'showCloseButton'	: false,
				'onStart'		:function(){$('#fancybox-outer').addClass('buyNowPopup');},
				'onClosed'			:function(){$('#fancybox-outer').removeClass('buyNowPopup');},
				'hideOnContentClick':false
       		}
       	);
		return false;
        
}

$(window).load(function(){
    shmugFix();
});

$(document).ready(function(){
	initFancybox();
	makeClearable("#site-search-txt", "Search");
	setCouponTracking();	
	//survey();
	$("#calloutid6").click(buyNow);
});

