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; }
    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="" src="/media/photos/img.jpg"/></a></span>
            <span>...</span>
            <span></span>
        </div>
    </div>
    
*/

function clips() {
    $(".recent-videos .teaser .clip a img").before(
        '<img class="video-overlay" src="' + base + '/images/121-video-overlay.gif" alt="" />'
    );
    $(".recent-posts .clip a img").before(
        '<img class="video-overlay" src="' + base + '/images/310-video-overlay.gif" alt="" />'
    );

    function over() {
        $(this).find(".video-overlay").show();
        // $(this).find("a").addClass("active");
    }
    function out() {
        $(this).find(".video-overlay").hide();
        // $(this).find("a").removeClass("active");
    }

    $(".clip").hover(over, out);
}

function photosets() {
    $(".recent-photos .teaser .photoset span a img").before(
        '<img class="photo-overlay" src="' + base + '/images/79-photo-overlay.gif" alt="" />'
    );
    $(".recent-posts .photoset span a img").before(
        '<img class="photo-overlay" src=' + base + '/images/184-photo-overlay.gif" alt="" />'
    );

    $(".supermodels .supermodel a img").before(
        '<img class="photo-overlay" src="' + base + '/images/231-photo-overlay.gif" alt="" />'
    );

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

    $(".photoset span").hover(over, out);
    $(".supermodel 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() {
    $(".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',
        hover: {
            color: '#FF598D'
        },
        hoverables: {
            span: true,
            a:true,
            li:true
        }
    });
    Cufon.replace(
        '#sidebar h3, #main-content > h1, #main-content h2, .modal-container h3', {
        fontFamily: 'Polaris',
        letterSpacing: '-0.25',
        textTransform: 'uppercase'
    });
    Cufon.replace(
        '#noflash h2', {
        fontFamily: 'Polaris',
        fontSize: '16px',
        letterSpacing: '-0.25',
        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'
    });
}
