function submitSearchForm () {
	$("#txtKeywords").val( $("#txtKeywords").val().replace(/<(?:.|\s)*?>/g, "") );
	submitForm();
}

function watchSearchForm(e) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 13){
        submitSearchForm();
        return false;
    }
}

var Viagra = function () {};

Viagra.init = function ( components ) {
    for (var i = 0; i < components.length; i++ ) {
        components[i].init();
    }
}

Viagra.ContentCallouts = {
	init : function () {
		$('.more .box').mouseover(function () {
			$(this).addClass('box_on');
		}).mouseout(function () {
			$(this).removeClass('box_on');
		});
	}
}

Viagra.Menu = {
    timeout_length : 500,
    close_timeout  : 0,
    current_item   : null,
    current_hilite : null,

    init : function () {
        var self = this;
        $('#main_nav > li').mouseover( function () { self.open( this ) });
        $('#main_nav > li').mouseout( function () { self.set_timer() });
        document.onclick = function () { self.close() };
        if ( self.section_to_highlight ) {
			$('#main_nav_item_' + self.section_to_highlight).addClass('inside');
        }
        var $last_menu_item = $("#main_nav_item_4");
        var $last_menu      = $("#main_nav :last-child ul");
        $last_menu.css(
			"margin",
			"0px 0px 0px "
			+ ($last_menu_item.width() - $last_menu.width() + 39 )
			+ "px"
		);
    },

    open : function ( e ) {
        var self = this;
        self.cancel_timer();
        self.close();
        self.current_item   = $(e).find('ul').css('visibility', 'visible');
        self.current_hilite = $(e).find('a').addClass('active');
    },

    close : function () {
        var self = this;
        if ( self.current_item ) {
            self.current_item.css('visibility', 'hidden');
            self.current_hilite.removeClass('active');
        }
    },

    set_timer : function () {
		var self = this;
        self.close_timeout = window.setTimeout(
            function () { self.close() },
            self.timeout_length
        );
    },

    cancel_timer : function () {
        var self = this;
        if ( self.close_timeout ) {
            window.clearTimeout( self.close_timeout );
            self.close_timeout = null;
        }
    }
};

Viagra.Flash = {
    // members ...
    min_version    : "9.0.0",
    default_width  : 580,
    default_height : 335,
    // methods ...
    embedSWF: function (opts) {
		var self = this;
		var $container = $(opts["container"] || '.flash_container');

		var id;
		if (opts["swf"]) {
			id = self._clean_swf_id( opts["swf"] );
		}
		else {
			id = "viagra_video_player"
		}

		// get the flashvars, and ...
		var flashvars = opts["flashvars"] || {};
		// make sure to include the fonts
		flashvars.fontsURLs = "common/swf/fonts/Arial.swf,common/swf/fonts/Gotham.swf"
		// add taggingXMLPath
		if(opts["taggingXMLPath"]) {
			flashvars.taggingXMLPath = opts["taggingXMLPath"]
		}

		$container.html("<div id='" + id + "'></div>");
		swfobject.embedSWF(
			opts["full_swf_path"] || "PublicResources/ContentAssets/" + opts["swf"],
			id,
			opts["width"]       || self.default_width,
			opts["height"]      || self.default_height,
			opts["min_version"] || self.min_version,
			opts["installer"]   || null,
			flashvars,
			opts["params"]      || { wmode : "opaque" },
			opts["attrs"]       || {},
			opts["callback"]    || function (e) {
				if (e.success == false) {
					self._populate_no_flash_message( $container, opts["swf"] );
				}
			}
		);
    },
  	embedVideo: function (opts) {
		var self = this;
		self.embedSWF({
		    full_swf_path : "common/swf/ViagraStandaloneVP.swf",
		    width         : "560",
		    height        : "315",
		    installer     : "ViagraStandaloneVP",

		    flashvars: { dataHTMLstr: self._generate_dataHTML_str(opts), taggingXMLPath:'common/swf/xml/omniture_matrix.xml', deepLinkingXMLPath:'common/swf/xml/deeplink_matrix.xml' },
		    attrs         : { id : "ViagraStandaloneVP" },
		    params        : {
		        menu              : "false",
    			scale             : "noScale",
    			allowFullscreen   : "true",
    			allowScriptAccess : "always",
    			bgcolor           : "#869ca7",
    			wmode             : "opaque"

		    },
		    callback : function (e) {
				if (e.success == false) {
					self._populate_no_flash_message( $('.flash_container'), opts["id"] );
				}
			}
		})
    },
    embedQuestionsVideo: function (opts) {
		var self = this;

		var flashvars = opts["flashvars"] || {};
		// make sure to include the fonts
		flashvars.fontsURLs = "common/swf/fonts/Arial.swf,common/swf/fonts/Gotham.swf";
		flashvars.taggingXMLPath = 'common/swf/xml/omniture_matrix.xml';
		flashvars.deepLinkingXMLPath = 'common/swf/xml/deeplink_matrix.xml';
		flashvars.xmlSrc = 'common/swf/html_data/ViagraAccordion-config.html';

		self.embedSWF({
		    full_swf_path : "common/swf/ViagraAccordion.swf",
		    width         : "782",
		    height        : "761",
		    flashvars     : flashvars,
		    attrs         : { id : "ViagraAccordion" },
		    params        : {
				menu: "false",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				bgcolor: "#ffffff",
				wmode: "opaque"
		    },
		    callback : function (e) {
				if (e.success == false) {
					$(".flash_container").css("height" , "315px");
					$(".flash_container").css("width" , "560px");
					self._populate_no_flash_message( $('.flash_container'), opts["id"] );
				}
			}
		})
    },
    embedFCP: function (opts) {
		var self = this;
		var $container = $(opts["container"]);

		var id = ( opts["container"] );
		var new_id = id.replace('#', '');
		new_id = new_id.replace('container', 'embed');

		// get the flashvars, and ...
		var flashvars = opts["flashvars"] || {};
		// make sure to include the fonts
		flashvars.fontsURLs = "common/swf/fonts/Arial.swf,common/swf/fonts/Gotham.swf"
		flashvars.taggingXMLPath = 'common/swf/xml/omniture_matrix.xml';
		flashvars.deepLinkingXMLPath = 'common/swf/xml/deeplink_matrix.xml';
        flashvars.xmlSrc = 'common/swf/html_data/ViagraFCP-config_1_' + opts["index"] + '.html';

		$container.html("<div id='" + new_id + "'></div>");
		swfobject.embedSWF(
			opts["full_swf_path"] || "common/swf/ViagraStandaloneFCP.swf",
			new_id,
			opts["width"]       || 917,
			opts["height"]      || 335,
			opts["min_version"] || self.min_version,
			opts["installer"]   || null,
			flashvars,
			opts["params"]      || { wmode : "opaque" },
			opts["attrs"]       || {},
			opts["callback"]    || function (e) {
				if (e.success == false) {
					$(id).css("display" , "none");
				} else {
					$(id).next().css("display" , "none");
				}
			}
		);
    },
    embedMenuVideoPlayer : function (pageName) {
    	var self = this;
		self.embedSWF({
		    full_swf_path : "common/swf/ViagraMenuPlayer.swf",
		    width         : "792",
		    height        : "316",
		    installer     : "ViagraMenuPlayer",

		    flashvars: { dataHTMLstr: self._generate_dataHTML_for_MenuPlayer_str(pageName), taggingXMLPath: 'common/swf/xml/omniture_matrix.xml', deepLinkingXMLPath: 'common/swf/xml/deeplink_matrix.xml' },
		    attrs         : { id : "ViagraMenuPlayer" },
		    params        : {
		        menu              : "false",
    			scale             : "noScale",
    			allowFullscreen   : "true",
    			allowScriptAccess : "always",
    			bgcolor           : "#869ca7",
    			wmode             : "opaque"
		    },
		    callback : function (e) {
				if (e.success == false) {
					self._populate_no_flash_message( $('.flash_container'), pageName );
				}
			}
		})
    },
    _generate_dataHTML_str : function (opts) {
    	var plugin = opts["plugin"];
		var streaming = opts["streaming"];
		var videoTAG;
		
		if (plugin) {
			plugin += "?flv=../../PublicResources/VideoAssets/Videos/ImpSafetyInfo.flv";
		}
		
		if(streaming){
			videoTAG = "<video src='" + opts["videoURL"] + "' />" 
	    } else {
			videoTAG = "<video src='../../PublicResources/VideoAssets/Videos/" + opts["id"] + "_p" + opts["position"] + ".flv' />" 
        }
        
        var data = "<div id='videoPlayerContainer'>"
                 + videoTAG
                 + "<xml>"
                    + "<images>"
                        + "<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/" + opts["id"] + ".jpg' />"
                        + "<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/" + opts["id"] + "_end.jpg' />"
                        + "<img id='pausedBadge' src='' />"
                    + "</images>"
                    + "<plugin src='" + plugin + "' />"
                + "</xml>"
            + "</div>";
        if (encodeURIComponent) {
			data = encodeURIComponent(data);
		}
		return data;
    },

    _generate_dataHTML_for_MenuPlayer_str: function(pageName) {

        var str = '';
        if (pageName == 'tvpage') {

            var self = this;
            str = self._generate_dataHTML_for_CommercialPageMenuPlayer();
        } else if (pageName == 'counterfeit') {
            var self = this;
            str = self._generate_dataHTML_for_CounterfeitPageMenuPlayer();
        } else {  //default to testimonials page
		    str ="<div id='videoPlayerContainer'>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T1.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>How did ED affect you?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/Testimonial_1.jpg' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
							str+="<style verticalPadding='1' horizontalPadding='4' maxGap='4' gap='8' menuHeight='40' menuWidth='240'/>";
    					    str+="<plugin src='' />";
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T2.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>What did you think was causing your ED?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
    					    str+="<plugin src='' />";
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T3.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>How long did you wait before asking your doctor?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
    					    str+="<plugin src='' />";
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T4.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>How did you ask your doctor?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
    					    str+="<plugin src='../../PublicResources/VideoAssets/Videos/3.1.2_T6.flv' />"; 
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T5.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>How did your doctor react?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />"
    					    str+="</images>";
    					    str+="<plugin src='../../PublicResources/VideoAssets/Videos/3.1.2_T6.flv' />";  
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T6.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>How did you feel after the discussion?</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
    					    str+="<plugin src='../../PublicResources/VideoAssets/Videos/3.1.2_T6.flv' />";  
    				    str+="</xml>";
    			    str+="</video>";
    			    str+="<video src='../../PublicResources/VideoAssets/Videos/3.1.2_T7.flv'>"; 
    				    str+="<xml>";
    					    str+="<title>What is the safety of VIAGRA? (With Dr. Steven Lamm)</title>";
    					    str+="<images>";
    						    str+="<img id='startBadge' src='' />";
    						    str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Testimonial_post.jpg' />";
    						    str+="<img id='pausedBadge' src='' />";
    					    str+="</images>";
    					    str+="<plugin src='../../PublicResources/VideoAssets/Videos/3.1.2_T6.flv' />";  
    				    str+="</xml>";
    			    str+="</video>";
    		    str+="</div>";

	    }

	    if (encodeURIComponent) {
	        str = encodeURIComponent(str);
	    }

	    return str;
	},
	_generate_dataHTML_for_CounterfeitPageMenuPlayer: function() {
	var str = "<div id='videoPlayerContainer'>";
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/01ACounterfeitEpidemic.flv'>"; 
			str+="<xml>";
				str+="<title>A Counterfeit Epidemic</title>";
				str+="<images>";
				str+="<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/CounterfeitEpidemic_title.jpg' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.1_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='2' horizontalPadding='2' maxGap='3' gap='8' menuHeight='30.666' menuWidth='238'/>";
				str+="<plugin src='' />";
			str+="</xml>";
		str+="</video>";
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/02RecipeForAFake.flv'>"; 
			str+="<xml>";
				str+="<title>Recipe for a Fake</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.2_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";
		str+="</video>";
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/03TheCounterfeitNetwork.flv'>"; 
			str+="<xml>";
				str+="<title>The Counterfeit Network</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.3_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";
		str+="</video>";
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/04OnlinePharmacyScams.flv'>"; 
			str+="<xml>";
				str+="<title>Online Pharmacy Scams</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.4_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/05CollectingTheEvidence.flv'>"; 
			str+="<xml>";
				str+="<title>Collecting the Evidence</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.5_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";		
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/06SearchingForFakes.flv'>"; 
			str+="<xml>";
				str+="<title>Searching for Fakes</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.6_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";	
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/07CounterfeitingAndBeyond.flv'>"; 
			str+="<xml>";
				str+="<title>Counterfeiting and Beyond</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.7_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";			
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/08PfizerGlobalSecurity.flv'>"; 
			str+="<xml>";
				str+="<title>Pfizer Global Security</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.8_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";			
		str+="<video src='rtmp://cp70870.edgefcs.net/ondemand/flash/viagra/stage/09BuyingMedicineSafelyOnline.flv'>"; 
			str+="<xml>";
				str+="<title>Buying Medicine Safely Online</title>";
				str+="<images>";
				str+="<img id='startBadge' src='' />";
				str+="<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/4.6.9_end.jpg' />";
				str+="<img id='pausedBadge' src='' />";
				str+="</images>";
				str+="<style verticalPadding='1' horizontalPadding='3' maxGap='4' menuHeight='32'/>";
				str+="<plugin src='' />";
			str+="</xml>";			
		str+="</video>";			
	str+="</div>";
    	return str;
	},
	_generate_dataHTML_for_CommercialPageMenuPlayer: function() {
		var str = "<div id='videoPlayerContainer'>";
		    	str += "<video src='../../PublicResources/VideoAssets/Videos/F.5.3.flv'>"; 
    				str+="<xml>";
    					str+="<title>Click to play \"Sail\"</title>";
    					str+="<images>";
    					    str += "<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/Sail-slate_03.jpg' />";
    						str += "<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/Sail_slate_04.jpg' />";
    						str+="<img id='pausedBadge' src='' />";
    					str+="</images>";
						str+="<style verticalPadding='1' horizontalPadding='4' maxGap='4' menuHeight='40' menuWidth='240'/>";
    					str += "<plugin src='' />";  
    				str+="</xml>";
    			str+="</video>";
		    str += "<video src='../../PublicResources/VideoAssets/Videos/F.5.1.flv'>"; 
    				str+="<xml>";
    					str+="<title>Click to play \"Stuck\"</title>";
    					str+="<images>";
    					    str += "<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/stuck.jpg' />";
    						str += "<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/tv_stuck_end.jpg' />";
    						str+="<img id='pausedBadge' src='' />";
    					str+="</images>";
						str+="<style verticalPadding='1' horizontalPadding='4' maxGap='4' menuHeight='40' menuWidth='240'/>";
    					str += "<plugin src='' />";  
    				str+="</xml>";
    			str+="</video>";
    			    str += "<video src='../../PublicResources/VideoAssets/Videos/F.5_p1.flv'>"; 
    				str+="<xml>";
    					str+="<title>Click to play \"Gas Station\"</title>";
    					str+="<images>";
    					    str += "<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/gas_station.jpg' />";
    						str += "<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/tv_gasstation_end.jpg' />";
    						str+="<img id='pausedBadge' src='' />";
    					str+="</images>";
    					str+="<plugin src='' />";  
    				str+="</xml>";
    			str+="</video>";
    			    str += "<video src='../../PublicResources/VideoAssets/Videos/F.5.2.flv'>"; 
    				str+="<xml>";
    					str+="<title>Click to play \"Anthem\"</title>";
    					str+="<images>";
    					    str += "<img id='startBadge' src='../../PublicResources/VideoAssets/PreRoll/anthem.jpg' />";
    						str += "<img id='endBadge' src='../../PublicResources/VideoAssets/PostRoll/tv_anthem_end.jpg' />";
    						str+="<img id='pausedBadge' src='' />";
    					str+="</images>";
    					str+="<plugin src='' />";  
    				str+="</xml>";
    			str+="</video>";
    		str+="</div>";
    	return str;
    },
    _clean_swf_id : function (id) {
		return id.replace('.', '_').replace('/', '_');
    },
    _populate_no_flash_message : function (e, id) {
		var out = "<a target='_blank' href='http://get.adobe.com/flashplayer/'><img style='margin:0px' src='common/images/";
		if (id == 'menu') {
			out += "3.1.2_NOFLASH.jpg";
		}
		else if (id == 'testimonials') {
			out += "3.1.2_NOFLASH.jpg";
		}
		else if (id == 'counterfeit') {
			out += "4.6_NOFLASH.jpg";
		}
		else if (id == 'ViagraAccordion') {
			out += "Video_NOFLASH.jpg";
		}
		else if (id == '1.4.1_p1.swf' || id == '2.3.1_p1.swf') {
			out += "1.4.1_2.3.1_NOFLASH.jpg";
		}
		else if (id == '2_4/2.4_p1.swf') {
			out += "2.4_NOFLASH.jpg";
		}
		else if (id == '4_3/4.3_p1.swf') {
			out += "4.3_NOFLASH.jpg";
		}
		else {
			out += "Video_NOFLASH.jpg";
		}
		$(e).html(out + "' border='0' /></a>");
    }
};

Viagra.Carousel = {
    // members ...
    item_width  : 310,
    num_visible : 3,
    num_items   : 7,
    max_scroll  : 4,
    nav         : null,
    carousel    : null,
    anchor      : null,
    // state info ...
    current_lightbox_index : null,
    current_scroll_index   : null,
    is_carousel_active     : true,
    auto_scroll_interval   : null,
    // methods ....
    init : function () {

        if ($('.main_carousel').length == 0) return;

		var self = this;

        self.carousel = $('.main_carousel_inner');
        self.nav      = $('.main_carousel_nav');

        var url = document.location.toString();
        if (url.match('#')) {
			self.anchor = url.split('#')[1];
			self.scrollTo( self.anchor );
		}
		else {
			self.scrollTo( 0 );
		}

        self.nav.find('.forward').click(function () {
            self.scrollBy( -self.item_width );
			clearInterval( self.auto_scroll_interval );
			self.startAutoScroll();
        });

        self.nav.find('.back').click(function () {
            var is_first_box = ($('#carousel_first_box').attr('class') == "box box_on");
            if(is_first_box == true) {
            	$("#new_box").click();
            } else {
            self.scrollBy( self.item_width );
            clearInterval( self.auto_scroll_interval );
            self.startAutoScroll();
            }
        });

        /*
        self.nav.find('.box').each(function (i) {
            var pos = self.num_items - (i + 1);
            $(this).click(function () {
                self.scrollTo( pos );
                clearInterval( self.auto_scroll_interval );
                self.startAutoScroll();
            })
        });
        */

       $('.main_lightbox_menu_item').each(function () {
        	$(this).css("cursor", "pointer");
			$(this).click(function () {
				$('.main_lightbox_menu_item').removeClass('li_on');
				$('.main_lightbox_blurb_div').hide();
				$(this).addClass('li_on');
				$('#' + $(this).attr('id').replace('menu', 'content')).show();
			});
		});

		self.startAutoScroll();
    },

    startAutoScroll : function () {
		var self = this;
		self.auto_scroll_interval = setInterval(function () {
			if (self.current_scroll_index == self.max_scroll) {
				self.scrollTo( 0, 200 );
			}
			else {
				self.scrollTo( self.current_scroll_index + 1, 400 );
			}
		}, 5000);
    },

    scrollBy : function ( distance ) {
		var self = this;

        var current_left = parseInt( self.carousel.css('left') );
        var state        = Math.abs( current_left / self.item_width );

        var going_back    = distance > 0;
        var going_forward = distance < 0;

        if (state                    == 0              && going_back    == true) return;
        if (state + self.num_visible == self.num_items && going_forward == true) return;

		if (self.is_carousel_active == false) return;
		self.is_carousel_active = false;

        self.carousel.animate(
			{ left : current_left + distance },
			200,
			function () { self.is_carousel_active = true }
		);
        self.setNavState( going_back ? --state : ++state );
    },

    scrollTo : function ( index, speed ) {
        var self = this;

        if (self.is_carousel_active == false) return;
        self.is_carousel_active = false;

        var max_index = Math.min( index, self.max_scroll );
        self.carousel.animate(
			{ left : -( max_index * self.item_width) },
			speed || 200,
			function () { self.is_carousel_active = true }
		);
        self.setNavState( max_index );
    },

    setNavState : function ( start ) {
        var self = this;

        var $boxes = self.nav.find('.box');
        $boxes.removeClass('box_on');

        var real_start;

        if (start == null) {
            real_start = (self.num_items - 1);
        }
        else {
            real_start = (self.num_items - start) - 1;
        }

        for ( var i = 0; i < self.num_visible ; i++ ) {
            $boxes.eq( real_start-- ).addClass('box_on');
        }

        self.current_scroll_index = start;
    },

    showLightBoxBackUp: function ( index ) {
        var self = this;
        var $box = $('#main_carousel_lightbox_' + index);
        Viagra.Flash.embedFCP({
            "index"     : index,
            "container" : "#fcp" + index + "_flash_container"
        });
		$box.fadeIn( 200 , null );
		$box.find('.main_lightbox_menu_item:first').click();
		self.current_lightbox_index = index;
		clearInterval( self.auto_scroll_interval );

    },



    showLightBox: function( index, pagename, evar29 ) {

        var self = this;

        var $box = $('#main_carousel_lightbox_' + index);

        Viagra.Flash.embedFCP({

            "index": index,

            "container": "#fcp" + index + "_flash_container"

        });

        $box.fadeIn(200, null);

        $box.find('.main_lightbox_menu_item:first').click();

        self.current_lightbox_index = index;

        clearInterval(self.auto_scroll_interval);

        self.trackShowLightBox(pagename, evar29);

    },    
    trackShowLightBox: function( pagename, evar29 ) {

        s.pageName = s.prop3 = s.eVar3 = pagename;
        s.prop12 = 'lightbox:buttons';
        s.prop27 = s.eVar27 = 'routers';
        s.prop29 = s.eVar29 = evar29;
        s.prop1 = 'home';
        s.t();
    },
    hideLightBox: function () {
		var self = this;
		$('#main_carousel_lightbox_' + self.current_lightbox_index).fadeOut( 200 , null );
		$("#fcp" + self.current_lightbox_index + "_flash_container").html("");
		self.startAutoScroll();
    },

	show_new_carousel: function() {
		Viagra.Carousel.scrollTo( 0, 200 );
		clearInterval(Viagra.Carousel.auto_scroll_interval);
		
		Viagra.Carousel.trackShowLightBox('home:fcp 1-6 lightbox callout:Counterfeiters are smart:Click to Watch Video Series', 'anti counterfeit');
	
		$(".new_box").attr('class', 'new_box_on');
	
		$('.main_carousel_nav span.box').removeClass('box_on');
	
		$('.main_carousel_nav span.box').addClass('box_off');
		$('.main_carousel_nav a.forward').addClass('forward_off');
		$('.main_carousel_nav a.back').addClass('back_off');
		
		var current_image = 2;
		
		var new_carousel_interval = setInterval( function() {
			if (current_image < 6) {
				$('#new_carousel_dynamic_image').fadeOut(800, function() {
					$('#new_carousel_dynamic_image').css('background-image','url(common/images/new_carousel/slide'+current_image+'.jpg)');
					$('#new_carousel_dynamic_image').fadeIn(800, function() {
						current_image++;
					});
				});
			} else {
				clearInterval(new_carousel_interval);
				setTimeout(Viagra.Carousel.return_to_carousel,1200);
			}
		}, 2500);
		
		$(".box, .forward").click(function() {
			if($("#new_box").attr('class') == 'new_box_on') {
				clearInterval(new_carousel_interval);
				setTimeout(Viagra.Carousel.return_to_carousel,1200);
			}
		});
	},

	return_to_carousel: function() {
		$('.main_carousel_nav span.box_off').removeClass('box_off');
		$('.main_carousel_nav a.forward_off').removeClass('forward_off');
		$('.main_carousel_nav a.back_off').removeClass('back_off');
		
		$(".new_box_on").attr('class', 'new_box');
		
		Viagra.Carousel.scrollTo( 0, 200 );
		clearInterval(Viagra.Carousel.auto_scroll_interval);
		
		$('#new_carousel').fadeOut(800, function() {
			clearInterval(Viagra.Carousel.auto_scroll_interval);
			Viagra.Carousel.startAutoScroll();
		});
	}

};


$(document).ready( function() {
		
		$('#new_carousel').click(function() { window.location = "/buy-real-viagra/counterfeit-viagra-videos.aspx" });
		
		$("#new_box").click(function() {
			if($("#new_box").attr('class') != 'new_box_on') {
				$('#new_carousel_dynamic_image').css('background-image','url(common/images/new_carousel/slide1.jpg)');
				$('#new_carousel').fadeIn(800, function() {
					Viagra.Carousel.show_new_carousel();
				});
				
				
			}
		});

});


new_carousel_image1 = new Image();
new_carousel_image1.src = "common/images/new_carousel/slide1.jpg";
new_carousel_image2 = new Image();
new_carousel_image2.src = "common/images/new_carousel/slide2.jpg";
new_carousel_image3 = new Image();
new_carousel_image3.src = "common/images/new_carousel/slide3.jpg";
new_carousel_image4 = new Image();
new_carousel_image4.src = "common/images/new_carousel/slide4.jpg";
new_carousel_image5 = new Image();
new_carousel_image5.src = "common/images/new_carousel/slide5.jpg";



// DFA Floodlight tag for the VIPPS links

function passed1(theLink) {
	window.open(theLink);
}
function trackclick1(theLink) {
	var axel = Math.random() + "";
	var a = axel * 1000000000000000000;
	var spotpix = new Image();
	spotpix.src = 'http://fls.doubleclick.net/activityi;src=733866;type=vgcsv;cat=vipps;u2=VIPPS_Link;ord=' + a + '?';
	spotpix.onload = passed1(theLink);
}


// anatomy popup fix

/*$(document).ready( function() {
	$('a[href$="buy-real-viagra/illegitimate-online-pharmacy.aspx"]')
		.attr('href',"/illegitimate-online-pharmacy.aspx")
		.attr('target',"_blank")
});*/







