function navigation() {
    // Make sure they are hidden
    $(".nav-container").hide();
    $(".nav-container .model-icon").hide();

    // apply on hover effect to navigation dropdown
	$("#nav ul li.dropdown").hover(
    function () {
        $(this).addClass("active");
        $(this).children("span").addClass("active");
		$(this).children("ul").show();
        Cufon.refresh('#nav ul > li span');
    },
    function(){
        $(this).removeClass("active");
        $(this).children("span").removeClass("active");
		$(this).children("ul").hide();
		Cufon.refresh('#nav ul > li span');
	  });

    // apply on hover effect to dropdown items
    $(".nav-container li div").hover(
        function() {
          $(this).children("div").show();
        },
        function() {
          $(this).children("div").hide();
    }
  );
}

function shareTextSelect() {
    $(".share-link").click(
    function() {
        $(this).focus();
        $(this).select();
    });
}

function sharing() {
    if ($("#page-wrap").hasClass("info-page")) { return; }
    if ($('#container').hasClass("silverlight")) { return; }

    var e = encodeURIComponent;
    var loc = window.location;
    var title = document.title;
    var sharingLinks = $(".social-icon", "#main-content");
    
    jQuery.each(sharingLinks, function() {
        var link = 'http://www.VSAllAccess.com/';
        var shareCopy = "There's more where this came from. Check VSAllAccess.com for more behind-the-scenes action, pics and videos! It's the new go-to for everything Victoria's Secret.";
        var twitterCopy = "Look what I found on VSAllAccess.com! ";
        if ($(this).hasClass("facebook-icon")) {
            link = 'http://www.facebook.com/sharer.php?src=bm&v=4&i=1253714522&u=' + e(loc.href) + '&t=' + e(title);
        }
        else if ($(this).hasClass("twitter-icon")) {
            link = 'http://twitter.com/home?status=' + twitterCopy + loc.href;
        }
        else if ($(this).hasClass('myspace-icon')) {
            link = 'http://www.myspace.com/index.cfm?fuseaction=postto&amp;u=' + e(loc.href) + '&amp;c=' + e(shareCopy) + '&amp;l=1';
        }
        else if ($(this).hasClass('digg-icon')) {
            link = 'http://digg.com/submit?url=' + e(loc.href) + '&amp;title=' + e(title) + '&amp;bodytext=' + e(shareCopy);
        }
        else if ($(this).hasClass('delicious-icon')) {
            link = 'http://delicious.com/save?url=' + e(loc.href) + '&title=' + e(title) + '&notes=' + e(shareCopy);
        }
        else if ($(this).hasClass('stumbleupon-icon')) {
            link = 'http://www.stumbleupon.com/submit?url=' + e(loc.href) + '&title=' + e(title);
        }
        else if ($(this).hasClass('email-icon')) {
            link = 'mailto:yourfriend%40example.com?subject=Check%20out%20the%20NEW%20VSAllAccess.com&body=' + e(shareCopy) +'%0D%0A%0D%0A' + e(loc.href);
        }
        $(this).children("a").attr('href', link);
        $(this).children("a").addClass('popup');
    });

    // adjust value of text to copy
    $("#main-content .share-link").attr('value', loc.href);
}

function popUpWindow(url, width, height, resizable, scrollbars){

	if (arguments.length == 1){
		width = 600;
		height = 400;
		resizable = "yes";
		scrollbars = "yes";
	}else if (arguments.length == 3){
		resizable = "no";
		scrollbars = "no";
	}else if (arguments.length == 4){
		scrollbars = "no";
	}

	var win = window.open(url, "PopUp", "width=" + width + ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",menubar=no,toolbar=no,left=20,top=20");
	return false;

}

function popups() {
    $('.popup').click(function() {
        popUpWindow(this.href);
        return false;
    });
    $('.popup-alt').click(function() {
       window.open(this.href, "_vswin");
       return false; 
    });
}


/*
    Add pink image overlays over teasers on hover to photosets and videos
    
    Example:
    
    <div class="teaser">
        <h4><a href="#">My Photoset</a></h4>
        <p class="alt-text">19 Photos</p>
        <div class="photoset">
            <span><img alt="" width="79px" height="79px" src="/media/photos/img.jpg"/></a></span>
            <span>...</span>
            <span></span>
        </div>
    </div>
    
*/

function clips() {

    function addOverlay() {
        var clipHeight = $(this).height();
        var clipWidth = $(this).width();
        if (jQuery.support.boxModel) {
            clipHeight = clipHeight - 12;
            clipWidth = clipWidth - 12;
        }
        $(this).before('<div class="overlay" style="width:'+ clipWidth +'px;height:'+ clipHeight +'px">&nbsp;</div>')
    }

    function over() {
        $(this).find(".overlay").show();
    }
    function out() {
        $(this).find(".overlay").hide();
    }

    $('.clip a img').each(addOverlay);
    $(".clip").hover(over, out);
}

function photosets() {

    function addOverlay() {
        var photosetHeight = $(this).height();
        var photosetWidth = $(this).width();
        if (jQuery.support.boxModel) {
            photosetHeight = photosetHeight - 12;
            photosetWidth = photosetWidth - 12;
        }
        $(this).before('<div class="overlay" style="width:'+ photosetWidth +'px;height:'+ photosetHeight +'px">&nbsp;</div>')
    }

    function over() {
        $(this).find(".overlay").show();
    }
    function out() {
        $(this).find(".overlay").hide();
    }

    $('.photoset span img').each(addOverlay);
    $('.channel img').each(addOverlay);
    $('.supermodel img').each(addOverlay);
    $('.post img').each(addOverlay);

    $(".photoset span").hover(over, out);
    $(".supermodel a").hover(over, out);
    $(".channel a").hover(over, out);
    $(".post a").hover(over, out);
}

/*
    Add a trigger anchor element marked with the class `modal-trigger'
    and with a rel attribute containing the jQurey selector of the overlay
    you want to show.
    
    Example:
    
    <a class="modal-trigger" rel="div.sharing" href="#">Share</a>

    <div class="modal-container sharing"></div>

*/

function overlays() {
    if ($('#container').hasClass("silverlight")) {
        $(".modal-trigger").click(function() {
            window.open('/about/share-popup.html', "share", "width=400,height=240,resizeable=no,menubar=no,scrollable=no");
            return false;
        })
    } else {
        $(".modal-trigger[rel]").overlay({
            close: '.modal-close',
            top: 100,
            expose: {
                color: '#000',
                loadSpeed: 200,
                opacity: 0.85
            }
        });
    }    
}

function fontReplace() {
    Cufon.replace('#nav ul > li span', {
        fontFamily: 'Avenir',
        fontSize: '15px',
        hover: {
            color: '#FF598D'
        },
        hoverables: {
            span: true,
            a:true,
            li:true
        }
    });
    Cufon.replace('#sidebar h3, #main-content h2, .modal-container h3, #supermodels-bar h2', {
        color: '#FF598D',
        fontFamily: 'Polaris',
        fontSize: '20px',
        letterSpacing: '-0.25',
        lineHeight: '20px',
        textTransform: 'uppercase'
    });
    Cufon.replace('#main-content > h1', {
        color: '#FFFFFF',
        fontFamily: 'Polaris',
        fontSize: '32px',
        letterSpacing: '-0.25',
        lineHeight: '32px',
        textTransform: 'uppercase'
    });
    Cufon.replace(
        '#noflash h2', {
        fontFamily: 'Polaris',
        fontSize: '16px',
        letterSpacing: '-0.25',
        lineHeight: '16px',
        textTransform: 'uppercase'
    });
    Cufon.replace(
        '#noflash p', {
        fontFamily: 'Polaris',
        fontSize: '13px'
    });
    Cufon.replace(
        '.info-page h1', {
        fontFamily: 'Polaris',
        fontSize: '32px',
        letterSpacing: '-0.25',
        lineHeight: '33px',
        textTransform: 'uppercase'
    });
}