/*!
 * Copyright (c) 2010 Liberty Concepts
 * http://www.libertyconceots.com
 * All right reserved *
 * @version 1.0
 * @notes Put all jQuery code into engine.structure.allBrowsers
 *        engine.structure.ie is only for IE lte 8.0 browsers
 */

var engine = {
    structure: {
        init : function(){
            if (!jQuery.support.opacity) {
                this.ie();
                this.allBrowsers();
            }
            else {
                this.allBrowsers();
            }
        },
        ie : function(){
            $j("div.main-signup td:last-child").css({
                "padding-right":"1px"
            });
            $j("ul.soc-icons li:last-child, #videoPager li:last-child").css({
                "margin-right":"0px"
            });
            $j(".tab .content-item:last-child").css({
                "border-bottom":"none",
                "padding-bottom":"0"
            });
        },
        allBrowsers : function(){
            $j("div.bodypage div.tabs-system>div:gt(0)").css({"padding":"20px"});
            Cufon.replace("#menu>li>a", {
                textShadow: '0px -1px #053E6D',
                fontFamily: 'Museo Sans 500'
            });
            Cufon.replace("#pager li a", {
                textShadow: '0px -1px #053E6D',
                fontFamily: 'Museo Sans 700'
            });
            Cufon.replace("#sign-up-caption, #slideshow h2, #quote", {
                textShadow: '0px 1px #fff'
            });
            Cufon.replace(".text h2, #tabs, #sidebar2 h2.title", {
                textShadow: '0px 1px #fff',
                fontFamily: 'Museo Sans 700'
            });
            Cufon.replace("#sidebar ul.actionbox li a, #sidebar ul.actionbox li.contact div.icon", {
                color: '-linear-gradient(#25769F, #69B4D4)'
            });
            Cufon.replace("#breadcrumbs h1", {
                textShadow: '0px 1px #fff',
                color: '-linear-gradient(#25769F, #69B4D4)'
            });
            Cufon.replace("div.main-signup button, #sidebar ul.actionbox li.contact button")
            if ($j("ul.sf-menu").length) {
                $j("ul.sf-menu").supersubs({
                    minWidth:15,
                    maxWidth:30,
                    extraWidth:1
                }).superfish().find('ul').bgIframe({
                    opacity:false
                });
            }
            Cufon.replace("form.becomeamember button, .nh .video-info h2")
            /* $j("ul.sf-menu>li").bind("mouseenter mouseleave", function(e){
                if (e.type == 'mouseenter'){
                    console.log(e.currentTarget)
                    $j("#arrowindicator").position({ my: "bottom center", at: "top center", of: e.currentTarget, offset: "0 -25" }).css("display","inline");
                }
                if (e.type == 'mouseleave'){
                  $j("#arrowindicator").css("display","none");
                }
                e.stopPropagation();
            })
            $j("ul.sf-menu>li:first").trigger("mouseenter")*/
            $j("div.main-signup button, a.read-more").live("mouseover mouseout", function(event){
                if (event.type == "mouseover") {
                    $j(this).stop().animate({
                        "background-position":"0 -29px"
                    },300);
                }
                if (event.type == "mouseout") {
                    $j(this).stop().animate({
                        "background-position":"0 0"
                    },300)
                }
            });
            $j("#menu>li").live("mouseover mouseout", function(event){
                if (event.type == "mouseover") {
                    $j(this).stop().animate({
                        "background-position":"0 0"
                    },300);
                }
                if (event.type == "mouseout") {
                    $j(this).stop().animate({
                        "background-position":"0 43px"
                    },300)
                }
            });
            $j("#pager li").bind("mouseover mouseout", function(event){
                if (event.type == "mouseover") {
                    $j(this).find("span").stop().fadeTo(1000, 1);
                }
                if (event.type == "mouseout") {
                   $j(this).find("span").stop().fadeTo(1000, 0);
                }
            });
            $j("ul.actionbox li").bind("mouseover mouseout", function(event){
                if (event.type == "mouseover") {
                    $j(this).stop().animate({"background-position":"255px 27px"},500);
                    //$j(this).find("a").stop().animate({"background-color":"#EBE4D4"},500);
                    //$j(this).find("span").stop().animate({ top: 10 },50).animate({ top: 14 },50).animate({ top: 12 },50)
                }
                if (event.type == "mouseout") {
                   $j(this).stop().animate({"background-position":"248px 27px"},300);
                   //$j(this).find("a").stop().animate({"background-color":"transparent"},500);
                   //$j(this).find("span").stop().animate({ top: 10 },50).animate({ top: 14 },50).animate({ top: 12 },50)
                }
            });
            $j("#slideshow").cycle({
                fx: 'fade',
                timeout: 5000,
                pager: "#pager",
                pause: 1,
                containerResize: 1,
                cleartypeNoBg:   true,
                pagerAnchorBuilder:function(idx,slide){
                    return'#pager li:eq(' + (idx) + ') a';
                }
            });
            $j("#videoCycle").cycle({
                fx: 'shuffle',
                timeout: 0,
                speed:500,
                pager: "#videoPager",
                pause: 1,
                containerResize: 1,
                cleartypeNoBg:   true,
                pagerAnchorBuilder:function(idx,slide){
                    return'#videoPager li:eq(' + (idx) + ') a';
                }
            });
            if ($j("#homepageTabs").length) {
              $j("#homepageTabs>div:eq(1)").appendTo($j("#homepageTabs>div:eq(0)"));
              $j("#homepageTabs>div:eq(0) .tab").css("padding-bottom","0");
              $j("#homepageTabs>div:eq(0) .tab:eq(1)").css("padding-top","0")
            }
            $j("#homepageTabs").cycle({
                fx: 'fade',
                timeout: 0,
                speed:1000,
                pager: "#tabs",
                pause: 1,
                containerResize: 1,
                after: function(){
                    Cufon.replace("#tabs", {
                        textShadow: '0px 1px #fff',
                        fontFamily: 'Museo Sans 700'
                    });
                },
                cleartypeNoBg:   false,
                pagerAnchorBuilder:function(idx,slide){
                    return'#tabs li:eq(' + (idx) + ') a';
                }
            });
            $j("ul.soc-icons").fadingSiblings();
        }
    }
}

$j(function(){
    $j(".homepage div.excerpt").truncate(300)
    engine.structure.init();
    $j.fn.formLabels({labelParent:'form'});
    plugins.pageTools.init("#contentHere");
    plugins.externalLinks();
    plugins.flickrFeed();
});
