var Engine = {
	
	// Appends the class 'selected' to the current navigation link's parent.		
    linkTreatment: function() { 
        $("#navigation a").each(function() {
            var hreflink = $(this).attr("href");
            if (hreflink.toLowerCase() == location.href.toLowerCase()) {
                $(this).parent("li").addClass("selected");
            }
        });
    },
    // http://malsup.com/jquery/corner/
    roundedCorners: function() {
        $.getScript("lib/ext/jquery.corners.js",
        function() {
            $('.rounded').corner();
            $('#details').corner('tr br');
            $('.roundedt').corner('tl br');
            $('#navigation a').corner('tl tr');
            $('#features li a').corner('tl tr 5px');
        });
    },
    // http://cufon.shoqolate.com/generate/
    loadFonts: function() {
        $.getScript("lib/ext/Gotham_Bold_700-Gotham_Ultra_900.font.js",
        function() {
            Cufon.replace('h2', {
                fontFamily: 'Gotham Ultra',
                textShadow: '#000 1px 1px'
            });
            Cufon.replace('h3', {
                fontFamily: 'Gotham Bold',
                textShadow: '#000 1px 1px'
            });
            Cufon.replace('h4', {
                fontFamily: 'Gotham Bold',
                textShadow: '#000 1px 1px'
            });
           // Cufon.replace('#signup legend', {
          //      fontFamily: 'Gotham Ultra',
          //      textShadow: '#000 1px 1px'
          //  });
        });
    },
    loadCarousel: function() {
        $("#details .carousel").jCarouselLite({
            visible: 1,
            speed: 1000,
            btnNext: '.carousel .next',
            btnPrev: '.carousel .prev',
            beforeStart: function() {
                $('#screen img').animate({
                    opacity: 0
                },
                '10');
            },
            afterEnd: function() {
                $('#screen img').animate({
                    opacity: 1
                },
                '5500');
            }
        });
    },
    loadCarouselScreen: function() {
        $("#screen .screen-carousel").jCarouselLite({
            visible: 1,
            vertical: true,
            speed: 1000,
            btnNext: '.carousel .next',
            btnPrev: '.carousel .prev'
        });
    },
	
    lightBox: function() {
        $('a.gallery').colorbox({
            width: "80%",
            height: "80%",
            iframe: true,
            rel: 'promotions'
        });
		  $('a.screencap-link').colorbox({
            width: "80%",
            height: "80%",
            iframe: true,
            rel: 'promotions'
        });
        $('a.lightbox').colorbox({
            width: "1000px",
            height: "80%",
            iframe: true
        });
    },
	    exposeItem: function() {
        $.getScript("wp-content/themes/nutrapay/lib/ext/jquery.expose.js",
        function() { 
        	// assign a click event to the exposed element, using normal jQuery coding 
            $("#feature_list").click(function() { 
            	// perform exposing for the clicked element 
                $(this).expose({
                    api: true
                }).load();
            }); 
        });
    },
	// Main Feature Panel
    featureList: function() {
        $('head').append('<link rel="stylesheet" href="wp-content/themes/nutrapay/assets/css/ext/featured.css" type="text/css" />');
        $.getScript("wp-content/themes/nutrapay/lib/ext/jquery.featureList-1.0.0.js",
        function() {
            $('#features li a').featureList({
                output: '#output li',
                start_item: 5
            });
        });
    }

} 

// functions to run when the DOM is ready
$(document).ready(function() {
    Engine.linkTreatment();
    Engine.loadFonts();
    Engine.roundedCorners();
    Engine.loadCarousel();
    Engine.loadCarouselScreen();
    Engine.exposeItem();
	Engine.featureList();
    $("a[rel=external]").click(function() {
        window.open($(this).attr('href'));
        return false;
    });
}); 

// functions to run after page is fully loaded
$(window).load(function() {
						
    Engine.lightBox();
});