/* Create a namespace */
var CoverGirl = {};

function resetting() {
    $(".shoplanding h2#facelinkheader").css('background', 'url(' + faceLinkInActive + ')');
    $(".shoplanding h2#liplinkheader").css('background', 'url(' + lipLinkInActive + ')');
    $(".shoplanding h2#eyelinkheader").css('background', 'url(' + eyeLinkInActive + ')');
    $(".shoplanding h2#collectionlinkheader").css('background', 'url(' + collectionsLinkInActive + ')');
}


/* Functions to make the navigation work on Shop Products landing page */
function activateFace() {
    $(".shoplanding h2#liplinkheader").css('background', 'url(' + lipLinkInActive + ')');
    $(".shoplanding h2#eyelinkheader").css('background', 'url(' + eyeLinkInActive + ')');
    $(".shoplanding h2#collectionlinkheader").css('background', 'url(' + collectionsLinkInActive + ')');

    $(".shoplanding h2#facelinkheader").css('background', 'url(' + faceLinkActive + ')');
    $("ul#facelinks").fadeIn();
    $("ul#liplinks").fadeOut();
    $("ul#eyelinks").fadeOut();
    $("ul#collectionlinks").fadeOut();
    $("#facebg").fadeIn('normal', function() {
        $("#content").removeClass();
    });
    $("div.categorybackground:not('#facebg')").fadeOut();

}

function activateLips() {
    $(".shoplanding h2#facelinkheader").css('background', 'url(' + faceLinkInActive + ')');
    $(".shoplanding h2#eyelinkheader").css('background', 'url(' + eyeLinkInActive + ')');
    $(".shoplanding h2#collectionlinkheader").css('background', 'url(' + collectionsLinkInActive + ')');

    $(".shoplanding h2#liplinkheader").css('background', 'url(' + lipLinkActive + ')');

    $("ul#facelinks").fadeOut();
    $("ul#liplinks").fadeIn();
    $("ul#eyelinks").fadeOut();
    $("ul#collectionlinks").fadeOut();
    $("#lipsbg").fadeIn('normal', function() {
        $("#content").removeClass();
    });
    $("div.categorybackground:not('#lipsbg')").fadeOut();

}

function activateEyes() {
    $(".shoplanding h2#facelinkheader").css('background', 'url(' + faceLinkInActive + ')');
    $(".shoplanding h2#liplinkheader").css('background', 'url(' + lipLinkInActive + ')');
    $(".shoplanding h2#collectionlinkheader").css('background', 'url(' + collectionsLinkInActive + ')');

    $(".shoplanding h2#eyelinkheader").css('background', 'url(' + eyeLinkActive + ')');
    $("ul#facelinks").fadeOut();
    $("ul#liplinks").fadeOut();
    $("ul#eyelinks").fadeIn();
    $("ul#collectionlinks").fadeOut();
    $("#eyesbg").fadeIn('normal', function() {
        $("#content").removeClass();
    });
    $("div.categorybackground:not('#eyesbg')").fadeOut();

}

function activateCollection() {

    $(".shoplanding h2#facelinkheader").css('background', 'url(' + faceLinkInActive + ')');
    $(".shoplanding h2#liplinkheader").css('background', 'url(' + lipLinkInActive + ')');
    $(".shoplanding h2#eyelinkheader").css('background', 'url(' + eyeLinkInActive + ')');

    $(".shoplanding h2#collectionlinkheader").css('background', 'url(' + collectionsLinkActive + ')');
    $("ul#facelinks").fadeOut();
    $("ul#liplinks").fadeOut();
    $("ul#eyelinks").fadeOut();
    $("ul#collectionlinks").fadeIn();
    $("#collectionsbg").fadeIn('normal', function() {
        $("#content").removeClass();
    });
    $("div.categorybackground:not('#collectionsbg')").fadeOut();
}

/* Enable Shop Products landing page */
CoverGirl.enableShopProducts = function() {
    $('h2#facelinkheader a').focus(function() {
        activateFace();
    });
    $('h2#liplinkheader a').focus(function() {
        activateLips();

    });
    $('h2#eyelinkheader a').focus(function() {
        activateEyes();
    });
    $('h2#collectionlinkheader a').focus(function() {
        activateCollection();
    });

    $("h2#facelinkheader a").hover(
	  function() {
	      $('h2#facelinkheader a').focus();
	  },
	  function() {

	  }
	);
    $("h2#liplinkheader a").hover(
	  function() {
	      $('h2#liplinkheader a').focus();
	  },
	  function() {

	  }
	);
    $("h2#eyelinkheader a").hover(
	  function() {
	      $('h2#eyelinkheader a').focus();
	  },
	  function() {

	  }
	);
    $("h2#collectionlinkheader a").hover(
	  function() {
	      $('h2#collectionlinkheader a').focus();
	  },
	  function() {

	  }
	);

};
/* Beauty Chat Bubble scripts */
CoverGirl.enableBeautyBubble = function() {
    $("#beautychatbutton a").focus(function() {
        if (!$(this).hasClass("bubbleopen")) {
            beautyBubbleShow();
            beautyBubbleDelayedHide();
        }
    });

    $("#beautychatbutton").hover(
	  function() {
	      beautyBubbleShow();
	  },
	  function() {
	      beautyBubbleHide();
	  }
	);
};

function beautyBubbleShow() {
    if ($.support.leadingWhitespace) {
        $("#beautybubblecontent").fadeIn("fast"); // fade if not IE
    } else {
        $("#beautybubblecontent").show(); // just show if IE
    };
    $("#beautychatbutton a").addClass("bubbleopen")
}
function beautyBubbleHide() {
    if ($.support.leadingWhitespace) {
        $("#beautybubblecontent").fadeOut("fast"); // fade if not IE
    } else {
        $("#beautybubblecontent").hide(); // just hide if IE
    };
    $("#beautychatbutton a").removeClass("bubbleopen")
}
function beautyBubbleDelayedHide() {
    window.setTimeout('beautyBubbleHide()', 15000);
}

/* Reset all link for Filter Products */
/* (will probably need to be expanded in functionality later) */
CoverGirl.enableResetFilterLink = function() {
    $("a#filterreset").click(function() {
        var labels = $(this).parent("#productfiltersform").find("label");
        var checkboxes = $(this).parent("#productfiltersform").find("input");
        labels.removeClass();
        checkboxes.attr('checked', false).removeClass();
        return false;
    })
}


/* Product image switching, for Product Detail page */
CoverGirl.enableProductImageSwitch = function() {
    $("div.detailthumbs a").click(function() {
        var imageSource = $(this).attr("href");
        $("img#productdetailimage").attr("src", imageSource);
        return false;
    })
}

/* Expanding/contracting sections, for My Covergirl Colormatch page */
CoverGirl.enableExpandHide = function() {

    /* first set default for all toggle links and divs */
    $("div.productresults").hide();

    $('div.section a.togglelink').each(function(i) {
        $(this).addClass("openlink").text("open").attr("aria-expanded", "false");
        var controlledsection = $(this).parent("div.sectiontools").parent("div.section").find("div.productresults");
        var controlledsectionID = controlledsection.attr("id");
        $(this).attr("aria-controls", controlledsectionID);

    })

    /* then show the first one
    $('div.section a.togglelink:first').removeClass("openlink").addClass("closelink").text("close").attr("aria-expanded", "true");
    $("div.productresults:first").show(); */

    /* Toggle show/hide on click */
    $('div.section a.togglelink').click(function() {

        if ($(this).hasClass("openlink")) {
            $(this).removeClass("openlink").addClass("closelink").text("close").attr("aria-expanded", "true");
        } else {
            $(this).removeClass("closelink").addClass("openlink").text("open").attr("aria-expanded", "false");
        }

        $(this).parent("div.sectiontools").parent("div.section").find("div.productresults").toggle('normal');
        return false;
    });

}

/* Expanding/contracting sections, for My Covergirl Colorwatch page */
CoverGirl.enableExpandHideTips = function() {

    /* first set default for all toggle links and divs */
    $("div.tipsection div.tips").hide();
    $('div.tipsection a.togglelink').each(function(i) {
        $(this).addClass("openlink").text("open").attr("aria-expanded", "false");
        var controlledsection = $(this).parent("div.sectiontools").parents("div.tipsection").find("div.tips");
        var controlledsectionID = controlledsection.attr("id");
        $(this).attr("aria-controls", controlledsectionID);
    })

    /* then show the first one */
    $('div.tipsection a.togglelink:first').removeClass("openlink").addClass("closelink").text("close").attr("aria-expanded", "true");
    $("div.tips:first").show();

    /* Toggle show/hide on click */
    $('div.tipsection a.togglelink').click(function() {
        if ($(this).hasClass("openlink")) {
            $(this).removeClass("openlink").addClass("closelink").text("close").attr("aria-expanded", "true");
        } else {
            $(this).removeClass("closelink").addClass("openlink").text("open").attr("aria-expanded", "false");
        }

        $(this).parent("div.sectiontools").parents("div.tipsection").find("div.tips").toggle('normal');
        return false;
    });

}

var myWhatsNewClass;
var myWhatsNewLink;

function getMyLink(hoverdiv) {
    myWhatsNewClass = $(hoverdiv).attr("class");
    /* MindTree Changed "a#" to "a." as the IDs are generated by ASP.Net */
    myWhatsNewLink = $(".productlinks ol li a." + myWhatsNewClass);

}

CoverGirl.enableWhatsNewRollovers = function() {
    $("div#beautybuzzwhatsnew div#imagemap div")
		.hover(function() {
		    getMyLink(this);
		    $(myWhatsNewLink).addClass("hover");
		},
		  function() {
		      getMyLink(this);
		      $(myWhatsNewLink).removeClass("hover");
		  }
		)
		.click(function() {
		    getMyLink(this);

		    var myURL = $(myWhatsNewLink).attr("href");
		    window.location = myURL;
		});
}

CoverGirl.enableMollyMustHaveRollovers = function() {
    $("div.mollymusthaves div#imagemap div")
		.hover(function() {
		    getMyLink(this);
		    $(myWhatsNewLink).addClass("hover");
		},
		  function() {
		      getMyLink(this);
		      $(myWhatsNewLink).removeClass("hover");
		  }
		)
		.click(function() {
		    getMyLink(this);
		    var myURL = $(myWhatsNewLink).attr("href");
		    window.location = myURL;
		});
}

CoverGirl.enableBuzzAwardSwitch = function() {
    $("div.awardlogos a").click(function() {
        $(this).parent("div").find("a").removeClass("notselected");
        $("div.awarddescription").removeClass("selecteddescription");
        $(this).parent("div").find("a").not(this).addClass("notselected");
        var awardPicked = $(this).attr("class");
        $(this).parents("div.productcontent").find("div." + awardPicked).addClass("selecteddescription");
        return false;
    });
}


CoverGirl.enableSpecialOffers = function() {
    // initial defaults
    $("div#specialswelcome div#welcomebackgrounds img:first").fadeIn();
    $("div#specialsnav li:first").addClass("selected");
    $("div#specialoffers div:first").css("left", "auto").css("right", "0");

    $("div#specialsnav a").click(function() {
        $("div#specialsnav li").removeClass("selected");
        $(this).parent("li").addClass("selected");


        var myTarget = $(this).attr("href").substring(1);

        if ($("div#specialswelcome div#welcomebackgrounds img").hasClass(myTarget)) {
            $("." + myTarget).fadeIn();
            $("div#specialswelcome div#welcomebackgrounds img").not("." + myTarget).fadeOut();

        }
        $("div#specialoffers div").css("left", "-4000em").css("right", "auto");
        $("div#specialoffers div").css("display", "none");

        $("div#specialoffers div#" + myTarget).css("left", "auto").css("right", "0");
        $("div#specialoffers div#" + myTarget).css("display", "block");




        return false;
    });
}

CoverGirl.enableLooksLanding = function() {

    $("div#looksexpandinseason div.expandtext h3 a").focus(function() {
        activateLooksInSeason();
    });
    $("div#looksexpandgallery div.expandtext h3 a").focus(function() {
        activateLooksGallery();
    });
    $("div#looksexpandcglooks div.expandtext h3 a").focus(function() {
        activateLooksCGLooks();
    });

    var inseasonconfig = {
        over: activateLooksInSeason, // function = onMouseOver callback (REQUIRED)    
        timeout: 100, // number = milliseconds delay before onMouseOut    
        out: function() { } // function = onMouseOut callback (REQUIRED)    
    };
    var galleryconfig = {
        over: activateLooksGallery, // function = onMouseOver callback (REQUIRED)    
        timeout: 100, // number = milliseconds delay before onMouseOut    
        out: function() { } // function = onMouseOut callback (REQUIRED)    
    };
    var cglooksconfig = {
        over: activateLooksCGLooks, // function = onMouseOver callback (REQUIRED)    
        timeout: 100, // number = milliseconds delay before onMouseOut    
        out: function() { } // function = onMouseOut callback (REQUIRED)    
    };

    $("div#looksexpandinseason").hoverIntent(inseasonconfig);
    $("div#looksexpandgallery").hoverIntent(galleryconfig);
    $("div#looksexpandcglooks").hoverIntent(cglooksconfig);

}

function animateLooksLanding() {
    $("div#looksexpandinseason").animate(
		{ left: "0px" },
		550,
		function() {
		    $("div#looksexpandgallery").animate(
				{ left: "0px" },
				550,
				function() {
				    $("div#looksexpandcglooks").animate(
						{ left: "0px" },
						550,
						function() {
						    $("div.looksexpand h2").addClass("IEFix").removeClass("IEFix");
						    CoverGirl.enableLooksLanding();
						}
					)
				}
			)
		}
	);
}
function activateLooksDefault() {
    $("#lookslandingwelcome").addClass("looksdefault");
    $("div.categorybackground").fadeOut();


}
function activateLooksInSeason() {
    $("#inseasonbg").fadeIn('normal', function() {
        $("#lookslandingwelcome").removeClass();
    });
    $("div.categorybackground:not('#inseasonbg')").fadeOut();

    $("div.looksmask").removeClass("looksselected").addClass("looksunselected");
    $("div#looksexpandinseasonmask").removeClass("looksunselected").addClass("looksselected");
    $("div#lookslandingwelcome div.panelshadow").css("left", "218px").css("z-index", "5").show();
}
function activateLooksGallery() {
    $("#gallerybg").fadeIn('normal', function() {
        $("#lookslandingwelcome").removeClass();
    });
    $("div.categorybackground:not('#gallerybg')").fadeOut();

    $("div.looksmask").removeClass("looksselected").addClass("looksunselected");
    $("div#looksexpandgallerymask").removeClass("looksunselected").addClass("looksselected");
    $("div#lookslandingwelcome div.panelshadow").css("left", "369px").css("z-index", "3").show();
}
function activateLooksCGLooks() {
    $("#cglooksbg").fadeIn('normal', function() {
        $("#lookslandingwelcome").removeClass();
    });
    $("div.categorybackground:not('#cglooksbg')").fadeOut();

    $("div.looksmask").removeClass("looksselected").addClass("looksunselected");
    $("div#looksexpandcglooksmask").removeClass("looksunselected").addClass("looksselected");
    $("div#lookslandingwelcome div.panelshadow").css("left", "520px").css("z-index", "1").show();
}

/* Looks category landing scripts */

var myLooksClass;
var myLooksLink;
var myLooksImageBox;

function getMyLooksImageLink(hoverdiv) {
    myLooksClass = $(hoverdiv).children("img").attr("class");
    myLooksLink = $("#lookslist ul li a#" + myLooksClass);
}

function getMyLooksLinkImage(link) {
    myLooksClass = $(link).attr("id");
    myLooksImage = $("div.lookphoto img." + myLooksClass);
    myLooksImageBox = myLooksImage.parent("div");
}

CoverGirl.enableLooksRollovers = function() {
    var firstMouseover = 1;

    var myLookImageMouseover = {
        over: function() {
            getMyLooksImageLink(this);
            if (firstMouseover = 1) {
                $("div.lookphoto").not(this).fadeTo(100, 0.5);
                $("div#lookslist ul li a").not("#" + myLooksClass).fadeTo(100, 0.5);
                firstMouseover = 2;
            } else {
                $("div.lookphoto.active").fadeTo(100, 0.5).removeClass("active");
                $("div#lookslist ul li a.hover").fadeTo(100, 0.5).removeClass("hover");
            }
            $(this).fadeTo(100, 1).addClass("active");
            $(myLooksLink).fadeTo(100, 1).addClass("hover");
        },
        timeout: 100, // number = milliseconds delay before onMouseOut    
        out: function() {
            getMyLooksImageLink(this);
            $(myLooksLink).removeClass("hover");
        }
    };

    var myLookLinkMouseover = {
        over: function() {
            getMyLooksLinkImage(this);
            if (firstMouseover = 1) {
                $("div#lookslist ul li a").not(this).fadeTo(100, 0.5);
                $("div.lookphoto img").not("." + myLooksClass).parent("div.lookphoto").fadeTo(100, 0.5);
                firstMouseover = 2;
            } else {
                $("div.lookphoto.active").fadeTo(100, 0.5).removeClass("active");
                $("div#lookslist ul li a.hover").fadeTo(100, 0.5).removeClass("hover");
            }
            $(myLooksImageBox).fadeTo(100, 1).addClass("active");
            $(this).fadeTo(100, 1).addClass("hover");
        },
        timeout: 100,
        out: function() {
            $(this).removeClass("hover");

        }
    };

    $("div.lookphoto")
		.hoverIntent(myLookImageMouseover)
		.click(function() {
		    getMyLooksImageLink(this);
		    var myURL = $(myLooksLink).attr("href");
		    window.location = myURL;
		})

    $("div#lookslist ul li a").hoverIntent(myLookLinkMouseover);
}

function sizeStripes() {
    var sideNavHeight = $("div#looksdetailwelcome").height();
    $("div#looksdetailnav, div#looksdetailnavstripes").height(sideNavHeight);
}

function openLooksSideNav() {
    sizeStripes();
    $("div#looksdetailnav").css("z-index", 5);
    $("div#looksdetailnavstripes").css("z-index", 4);
    $("div#looksdetailnav a#looksdetailnavtoggle").fadeOut("normal", function() {
        $("div#looksdetailnav").animate({
            width: "136px"
        }, {
            duration: 550,
            queue: false,
            complete: function() {
                $("div#looksdetailscroller").fadeIn();
                $("div#looksdetailmodelnav, div#looksdetailmodelnav .sidesubnav a.sidenavitem").fadeIn();
                $("div#looksdetailnav a#looksdetailnavtoggle")
				.removeClass("otherlooks")
				.addClass("closedetailnav")
				.attr("aria-expanded", "true")
				.html("close")
				.fadeIn();
            }
        });

        $("div#looksdetailnavstripes").animate(
			{ left: "136px" },
			{ duration: 570, queue: false }
		);
    })


};

function closeLooksSideNav(linkDestination) {
    sizeStripes();
    $("div#looksdetailnav a#looksdetailnavtoggle").fadeOut("normal", function() {
        $("div#looksdetailscroller").fadeOut("normal", function() {
            $("div#looksdetailnav").animate({
                width: "20px"
            }, {
                duration: 550,
                queue: false,
                complete: function() {
                    if (linkDestination != "" && linkDestination != null) {
                        window.location = linkDestination;
                    } else {
                        $("div#looksdetailnav a#looksdetailnavtoggle")
						.removeClass("closedetailnav")
						.addClass("otherlooks")
						.attr("aria-expanded", "false")
						.html("<img src=\"/images/Looks/bg_otherlooks_link.gif\" alt=\"\" />Other Looks")
						.fadeIn();
                    }

                    $("div#looksdetailnav").css("overflow", "visible"); /*Added by MIndTree */
                    $("div#looksdetailnav").css("z-index", 2);
                    $("div#looksdetailnavstripes").css("z-index", 1);
                }
            });
            $("div#looksdetailnavstripes").animate(
				{ left: "20px" },
				{ duration: 530, queue: false }
			);
        });

        $("div#looksdetailmodelnav .sidesubnav a.sidenavitem").fadeOut("normal");
        $("div#looksdetailmodelnav").fadeOut("normal", function() {
            $("div#looksdetailnav").animate({
                width: "20px"
            }, {
                duration: 550,
                queue: false,
                complete: function() {
                    if (linkDestination != "" && linkDestination != null) {
                        window.location = linkDestination;
                    } else {
                        $("div#looksdetailnav a#looksdetailnavtoggle")
						.removeClass("closedetailnav")
						.addClass("otherlooks")
						.attr("aria-expanded", "false")
						.html("<img src=\"/images/Looks/bg_otherlooks_link.gif\" alt=\"\" />Other Looks")
						.fadeIn();
                    }
                    $("div#looksdetailnav").css("z-index", 2);
                    //Added by mindtree to get other looks link in the cg looks detail page
                    $("div#looksdetailnav").css("overflow", "visible");
                    $("div#looksdetailnavstripes").css("z-index", 1);
                }
            });
            $("div#looksdetailnavstripes").animate(
				{ left: "20px" },
				{ duration: 530, queue: false }
			);
        });
    });
}

CoverGirl.enableLooksSideNav = function() {
    $("div#looksdetailnav a#looksdetailnavtoggle")
	.attr("aria-expanded", "false")
	.click(function() {
	    if ($(this).hasClass("otherlooks")) {
	        openLooksSideNav();
	    } else {
	        closeLooksSideNav();
	    }
	    return false;
	});




    if ($("div#looksdetailscroller").length > 0) {
        $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-controls", "looksdetailscroller");
    } else {
        $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-controls", "looksdetailmodelnav");
    }

    $("div#looksdetailmodelnav li.selected h2 a").click(function() {
        return false;
    });

    $("div#looksdetailmodelnav li:not(.selected) h2 a").click(function() {
        // Set cookie to say we're coming from a different model
        $.cookie("cglooksSidenav", "sidenavdifferent");
        var linkDestination = $(this).attr("href");
        $("div#looksdetailmodelnav li.selected div.sidesubnav").slideUp("normal", function() {
            window.location = linkDestination;
        })
        return false;
    });

    $("div#looksdetailmodelnav li a.sidenavitem").click(function() {
        // Set cookie to say we're coming from the same model
        $.cookie("cglooksSidenav", "sidenavsame");
        var linkDestination = $(this).attr("href");
        closeLooksSideNav(linkDestination);
        return false;
    });

    $("div#looksdetailscrollcontent a.sidenavitem").click(function() {
        // Set cookie showing we came from the sidenav
        $.cookie("seasonalSidenav", "sidenav");
        var linkDestination = $(this).attr("href");
        closeLooksSideNav(linkDestination);
        return false;
    })

    $("div#looksdetailscroller a.scrollcontrol").attr("tabindex", 20000);

    $("div#looksdetailscroller").serialScroll({
        target: "#looksdetailscrollcontent",
        items: "a.sidenavitem",
        prev: "a.scrollprev",
        next: "a.scrollnext",
        axis: "y",
        duration: 700,
        force: true,
        cycle: false,
        lock: false,
        stop: true,
        start: 0,
        onBefore: function(e, elem, $pane, $items, pos) {
            $('a.scrollprev,a.scrollnext').css("visibility", "visible");
            if (pos == 0)
                $('a.scrollprev').css("visibility", "hidden");
            else if (pos == $items.length - 3)
                $('a.scrollnext').css("visibility", "hidden");
        }
    });
}

/* Covergirl Video Pop */

function popVideo() {
    $("div.videothumb a").attr("aria-expanded", "true");
    $("div#videopop").show();
    $("div#videopop a.close").focus();
}

function hideVideo() {
    $("div.videothumb a").attr("aria-expanded", "false")
    $("div#videopop").hide();
    $("li.videotabnav a").focus();
}

CoverGirl.enableVideoPop = function() {
    $("div.videothumb a")
	.attr("aria-expanded", "true")
	.attr("aria-controls", "videopop")
	.click(function() {
	    popVideo();
	    return false;
	});

    $("div#videopop a.close").click(function() {
        hideVideo();
        return false;
    });
}

/* Functions to make the backgrounds fade on Covergirl Looks landing page */
function activateTaylor() {
    $("div#cglooksintro ul li.modellink a").removeClass();
    $("div#cglooksintro ul li#taylorlinkheader a").addClass("active");
    $("div#taylorbg").css({ opacity: 1 }).fadeIn();
    $("div.modelbackground:not('#taylorbg')").css({ opacity: 1 }).fadeOut();
    //$("div#taylorbg").fadeIn();
    //$("div.modelbackground:not('#taylorbg')").fadeOut();
}
function activateDrew() {
    $("div#cglooksintro ul li.modellink a").removeClass();
    $("div#cglooksintro ul li#drewlinkheader a").addClass("active");
    $("div#drewbg").css({ opacity: 1 }).fadeIn();
    $("div.modelbackground:not('#drewbg')").css({ opacity: 1 }).fadeOut();
}
function activateQueen() {
    $("div#cglooksintro ul li.modellink a").removeClass();
    $("div#cglooksintro ul li#queenlinkheader a").addClass("active");
    $("div#queenbg").css({ opacity: 1 }).fadeIn();
    $("div.modelbackground:not('#queenbg')").css({ opacity: 1 }).fadeOut();
}
function activateEllen() {
    $("div#cglooksintro ul li.modellink a").removeClass();
    $("div#cglooksintro ul li#ellenlinkheader a").addClass("active");
    $("div#ellenbg").css({ opacity: 1 }).fadeIn();
    $("div.modelbackground:not('#ellenbg')").css({ opacity: 1 }).fadeOut();
}
function activateDania() {
    $("div#cglooksintro ul li.modellink a").removeClass();
    $("div#cglooksintro ul li#danialinkheader a").addClass("active");
    $("div#daniabg").css({ opacity: 1 }).fadeIn();
    $("div.modelbackground:not('#daniabg')").css({ opacity: 1 }).fadeOut();
}

/* Enable Shop Products landing page */
CoverGirl.enableCGLooksLanding = function() {
    $("div#cglooksintro ul li a").hover(
		function() {
		    $("#modelbackgrounds").cycle("stop");
		    activate($(this).parent());
		},
		function() {

		}
	).focus(function() {
	    $("#modelbackgrounds").cycle("stop");
	    activate($(this).parent());
	});


    function activate(x) {
        //debugger;
        var Length = x[0].id.length;
        var bgName = x[0].id.substr(0, Length - 10) + "bg";
        $("div#cglooksintro ul li.modellink a").removeClass();
        $("div#cglooksintro ul li#" + x[0].id + " a").addClass("active");
        $("div#" + bgName + "").css({ opacity: 1 }).fadeIn();
        $("div.modelbackground:not('#" + bgName + "')").css({ opacity: 1 }).fadeOut();
    }




    /*$("div#cglooksintro ul li#taylorlinkheader a")
    .focus(function() {
    activateTaylor();
    })
    .hover(
    function () {
    activateTaylor();
    }, 
    function () {
	    
    }
    );
	
	$("div#cglooksintro ul li#drewlinkheader a")
    .focus(function() {
    activateDrew();
    })
    .hover(
    function () {
    activateDrew();
    }, 
    function () {
	    
    }
    );
	
	$("div#cglooksintro ul li#queenlinkheader a")
    .focus(function() {
    activateQueen();
    })
    .hover(
    function () {
    activateQueen();
    }, 
    function () {
	    
    }
    );
	
	$("div#cglooksintro ul li#ellenlinkheader a")
    .focus(function() {
    activateEllen();
    })
    .hover(
    function () {
    activateEllen();
    }, 
    function () {
	    
    }
    );
	
	$("div#cglooksintro ul li#danialinkheader a")
    .focus(function() {
    activateDania();
    })
    .hover(
    function () {
    activateDania();
    }, 
    function () {
	    
    }
    );*/

};

//try to eliminate IE 6 flicker
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }

function calculateHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    return tallest;
}


/* Initialize everything when page is ready */
$(document).ready(function() {





    CoverGirl.enableShopProducts();

    /* Beauty Bubble */
    CoverGirl.enableBeautyBubble();

    /* Custom filters for subcategory page */
    $("#productfilters input").customInput();
    CoverGirl.enableResetFilterLink();

    /* Custom checkbox for Register page */
    $("#shoppingcartarea input").customInput();

    /* Custom checkbox for Mobile Popup page */
    $("#mobileModelbigPopup input").customInput();


    /* Custom checkboxes for product page */
    $("#productshades input").customInput();

    /* Custom checkboxes for discontinued product page */
    $("#discontinuedproductlist input").customInput();

    /* Custom checkboxes for shopping cart page */
    $("#basketcontent input").customInput();

    /* Custom checkboxes and radio buttons for Colormatch quizzes */
    $("#quizcontent fieldset input").customInput();

    /* Custom checkboxes and radio buttons for New Colormatch quizzes */
    $(".formrow table tr td input").customInput();

    /* Custom checkboxes and radio buttons for sign-in page */
    $("#registersignin #signinblock input").customInput();

    /* Custom checkboxes for converstion tool details page */
    $("#Overlay-container input").customInput();

    /* Custom checkbox for Register page */
    $("#optionalblock .signmeup input").customInput();



    /* Product page image switcher */
    CoverGirl.enableProductImageSwitch();

    /* Search box hint */
    $("#search input.searchbox").hint();

    /* Initialize tabs */
    $("#tabs").tabs({
        show: function(event, ui) {
            if ($("div#looksdetailnavstripes").length > 0) {
                sizeStripes();
            }
        },
        select: function(event, ui) {
            if ($("div#looksdetailnavstripes").length > 0) {
                sizeStripes();
            }
            if ($("div.videotab").length > 0) {
                popVideo();
            }
        }
    });

    if ($("div#looksdetailnavstripes").length > 0) {
        var $tabs = $("#tabs").tabs();
        var selectedtab = $tabs.tabs('option', 'selected');
        $tabs.tabs('select', selectedtab);
    }

    /* Equalize tabs if on Looks detail pages */
    if (($("body.cglooksdetail").length > 0) || ($("body.seasonallooksdetail").length > 0)) {
        $("#tabs").clone().attr("id", "tabsclone").insertAfter("#tabs");
        var tallestTab = calculateHeight($("#tabsclone > div"));
        $("#tabsclone").remove();
        //alert("The tallest tab is: " + tallestTab);
        $("#tabs div.ui-tabs-panel").css("height", tallestTab);
    }

    /* Enable show/hide on My Covergirl Colormatch page 
    CoverGirl.enableExpandHide();*/

    /* Enable rollovers on Beauty Buzz What's New page */
    CoverGirl.enableWhatsNewRollovers();

    /* Enable Award switches */
    CoverGirl.enableBuzzAwardSwitch();

    /* Enable Special Offers switching */
    CoverGirl.enableSpecialOffers();

    /* Custom checkboxs for Tips Submission page */
    $(".tipform input").customInput();

    /* Enable rollovers on Molly Tips Must Haves "imagemap" */
    CoverGirl.enableMollyMustHaveRollovers();

    /* Enable show/hide on Member Tips page */
    CoverGirl.enableExpandHideTips();

    /* Enable panel animations on Looks landing page */
    //CoverGirl.enableLooksLanding();

    /* Enable image-to-link rollovers on Looks category pages */
    CoverGirl.enableLooksRollovers();

    /* Enable sliding side nav on Looks detail pages */
    CoverGirl.enableLooksSideNav();

    /* Enable video pop on Looks detail pages */
    CoverGirl.enableVideoPop();

    /* Enable background transitions on Covergirl Looks landing page */
    CoverGirl.enableCGLooksLanding();

    // Cookies for Looks detail pages
    var seasonallookscookie, cglookscookie;

    // Pre-page-load Cookie check if Seasonal Looks Detail page
    // Setting initial state of sidenav
    if ($("body.seasonallooksdetail").length > 0) {
        seasonallookscookie = ($.cookie("seasonalSidenav") || "");

        if (seasonallookscookie == "") {
            // If cookie doesn't exist 
            // Set the css for the sidenav so it starts open.
            $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-expanded", "true");
            $("div#looksdetailnav").css("width", "136px");
            $("div#looksdetailnavstripes").css("left", "136px");
            $("div#looksdetailscroller").show();
            $("div#looksdetailnav").css("z-index", 5);
            $("div#looksdetailnavstripes").css("z-index", 4);
        } else {
            // If cookie does exist
            if (seasonallookscookie == "sidenav") {
                // They came from the sidenav
                // Start out with nav closed and other Looks link showing
                $("div#looksdetailnav a.otherlooks").show();
            } else {
                // They didn't come from the sidenav
                // Set the css for the sidenav so it starts open.
                $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-expanded", "true");
                $("div#looksdetailnav").css("width", "136px");
                $("div#looksdetailnavstripes").css("left", "136px");
                $("div#looksdetailscroller").show();
                $("div#looksdetailnav").css("z-index", 5);
                $("div#looksdetailnavstripes").css("z-index", 4);
            }
        }
    };

    // Pre-page-load Cookie check if CG Looks Detail page
    // Setting initial state of sidenav
    if ($("body.cglooksdetail").length > 0) {
        cglookscookie = ($.cookie("cglooksSidenav") || "");

        if (cglookscookie == "") {
            // If cookie doesn't exist
            // Set the css for the sidenav so it starts open.
            $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-expanded", "true");
            $("div#looksdetailnav").css("width", "136px");
            $("div#looksdetailnavstripes").css("left", "136px");
            $("div#looksdetailmodelnav").show();
            $("div#looksdetailnav").css("z-index", 5);
            $("div#looksdetailnavstripes").css("z-index", 4);
        } else {
            // If cookie does exist...
            if (cglookscookie == "notsidenav") {
                // Not coming from the sidenav
                // Set the css for the sidenav so it starts open.
                $("div#looksdetailnav a#looksdetailnavtoggle").attr("aria-expanded", "true");
                $("div#looksdetailnav").css("width", "136px");
                $("div#looksdetailnavstripes").css("left", "136px");
                $("div#looksdetailmodelnav").show();
                $("div#looksdetailnav").css("z-index", 5);
                $("div#looksdetailnavstripes").css("z-index", 4);
            } else {
                // Coming from the sidenav
                if (cglookscookie == "sidenavdifferent") {
                    // Coming from a different model, set the sidenav so it starts open.
                    $("div#looksdetailnav a#looksdetailnavtoggle")
					.removeClass("otherlooks")
					.addClass("closedetailnav")
					.attr("aria-expanded", "true")
					.html("close")
					.show();
                    $("div#looksdetailnav").css("width", "136px");
                    $("div#looksdetailnavstripes").css("left", "136px");
                    $("div#looksdetailmodelnav ul li.selected div.sidesubnav").hide();
                    $("div#looksdetailmodelnav").show();
                    $("div#looksdetailnav").css("z-index", 5);
                    $("div#looksdetailnavstripes").css("z-index", 4);
                } else if (cglookscookie == "sidenavsame") {
                    // Coming from the same model, sidenav starts closed
                    $("div#looksdetailnav a.otherlooks").show();
                }
            }
        }
    }
});



/* accordion for discontinued page2*/

$(document).ready(function() {

    $('h2.subheadercls').click(function() {

        $(this).parent().find('h2').removeClass('selected');
        $(this).parent().find('ul').hide();
        $(this).addClass('selected');
        $(this).next().next().fadeIn('slow');
    });
    $('ul.productlist li').click(function() {

        $('#subnav ul li').removeClass('selected');
        $(this).addClass('selected');

    });



/* New Development suresh */
  var linkDestination = $(this).attr("href");
       	 closeLooksSideNav(linkDestination);

 $("#looksdetailnav #looksdetailmodelnav ul li h2 a")
	.attr("aria-expanded", "true")
	.click(function() {
	        var linkDestination = $(this).attr("href");
       	 closeLooksSideNav(linkDestination);
               $("div#looksdetailmodelnav ul li.selected div.sidesubnav").slideDown("normal");
	
  });
/*
 $("h2#modelnavdrew a")
	.attr("aria-expanded", "false")
	.click(function() {
	        var linkDestination = $(this).attr("href");
       	 closeLooksSideNav(linkDestination);
});

 $("h2#modelnavqueen a")
	.attr("aria-expanded", "false")
	.click(function() {
	        var linkDestination = $(this).attr("href");
       	 closeLooksSideNav(linkDestination);
});

 $("h2#modelnavellen a")
	.attr("aria-expanded", "false")
	.click(function() {
	        var linkDestination = $(this).attr("href");
       	 closeLooksSideNav(linkDestination);
});*/

/* New Development  */



/* new one123 */
	/*var linkDestination = $(this).attr("href");
 	closeLooksSideNav(linkDestination);
      $("#looksdetailmodelnav").css('display':'none');
       $("#looksdetailnavtoggle").addClass('otherlooks');
       $("#looksdetailnav").css({height: '831px', overflow: 'visible',  width:'20px',z-index:'2'});*/

});


// Initialize when whole page is loaded
$(window).load(function() {
    animateLooksLanding();

    // Cookies for Looks detail pages
    var seasonallookscookie, cglookscookie;

    if ($("body.seasonallooksdetail").length > 0) {
        seasonallookscookie = ($.cookie("seasonalSidenav") || "");
    };

    if ($("body.cglooksdetail").length > 0) {
        cglookscookie = ($.cookie("cglooksSidenav") || "");
    };

    /* Load up side stripes on Looks detail pages, taking sIFR load time into account */
    var dlay = setInterval(function() {
        if (jQuery('.sIFR-replaced').length >= sIFR.replacements.length) {

            setTimeout(sizeStripes, 250);

            // Cookie check if Seasonal Looks Detail page
            if ($("body.seasonallooksdetail").length > 0) {
                if (seasonallookscookie == "") {
                    // If cookie doesn't exist, it's the first visit; close the revealed sidenav after a slight delay.
                    setTimeout(function() { closeLooksSideNav() }, 1000);
                } else {
                    // There is a cookie
                    if (seasonallookscookie != "sidenav") {
                        // They didn't come from the sidenav
                        // Close the sidenav after a short pause
                        setTimeout(function() { closeLooksSideNav() }, 1000);
                    }
                }
                // Reset the cookie
                $.cookie("seasonalSidenav", "notsidenav");
            }

            // Cookie check if Covergirl Looks Detail page
            if ($("body.cglooksdetail").length > 0) {

                if (cglookscookie == "") {
                    // If cookie doesn't exist, it's the first visit; close the revealed sidenav after a slight delay.
                    setTimeout(function() { closeLooksSideNav() }, 1000);
                } else {
                    // There is a cookie
                    if (cglookscookie == "notsidenav") {
                        // Not coming from the sidenav
                        // Close the revealed sidenav after a slight delay.
                        setTimeout(function() { closeLooksSideNav() }, 1000);
                    } else {
                        // Coming from the sidenav
                        if (cglookscookie == "sidenavdifferent") {
                            // Coming from a different model, sidenav is already open
                            // We need to expand the selected model thumbnails
                            $("div#looksdetailmodelnav ul li.selected div.sidesubnav").slideDown("normal");
                        }
                    }
                }
                // Reset the cookie
                $.cookie("cglooksSidenav", "notsidenav");
            }
            clearInterval(dlay);
        };
    }, 100);
})

$(document).ready(function() {

    /* To fixing the MAC Isues's */
    if ($.browser.mozilla) {
        //alert('HI its MOzilla');
        $('.custom-checkbox input, .custom-radio input').css('visibility', 'hidden');

    }
    /* if ($.browser.mac()) {
    $('#mainnav ul li div.columns').css('width','43em');
    }*/
});


/* Mobile Popup */

$(document).ready(function() {
    $('#mobileModelbigPopup #closeMobile').live('click', function() { $('#mobileModelbigPopup').hide(); });
});

function showMobilePopup(clientId) {
    obj = document.getElementById(clientId);
    var curleft = 0, curtop = 0;
    clientId = "#" + clientId;
    obj = $(clientId);

    var offset = obj.position();
    curleft = offset.left;
    curtop = offset.top;
    width = parseInt($(clientId).width());
    var widthval;
    if ($.browser.msie) {
        widthval = curleft + (width / 2);
    } else {
        widthval = curleft + (width / 2);
    }

    $('#mobileModelbigPopup').css('display', 'block');
    document.getElementById('mobileModelbigPopup').style.left = widthval + 'px';
    document.getElementById('mobileModelbigPopup').style.top = curtop - 35 + 'px';
}
