/**
 * ConstructionExchange.com User Interface
 */ 
//var CE = {

//    /**
//     * Init UI functions
//     */         
//    init: function () {
//        CE.navigation();
//    },
//    
//    /**
//     * Navigation
//     */               
//    navigation: function () {
//        var links = $j("#nav a");
//        links.bind("click", function () {
//            links.removeClass("current");
//            var tab = $j(this).addClass("current");
//            var target = tab.attr("target");
//            $j(".formSearch span").hide();
//            $j("#search-" + target).show();
//            $j(".formSearch input:first").val(target);      
//            return false;
//        });
//    }

//}    
//    

//$j(document).ready(function () {
//    $j('.over-apply').labelOver('over-apply-keyword');
//    $j('#apply-near').labelOver('over-apply-near');
//    CE.init();
//});

var CE = {

    /**
     * Init UI functions
     */         
    init: function () {
        CE.navigation();
    },
    
    /**
     * Navigation
     */               
    navigation: function () {
        var links = $j("#navTabs a");
        links.bind("click", function () {
            links.removeClass("current");
            var tab = $j(this).addClass("current");
            $j(".formSearchModule input:first").val(tab.attr("target"));
            
            $j(".formSearchModule .blurb").each(function(){
                    $j(this).hide()
            });
            
            $j("#p" + tab.attr("target")).show();
            
            return false;
        });
    }
}    

var currentTab = 0;
function mycarousel_initCallback(carousel){

    $j(".frame1").each(function(){
        $j(this).removeClass('inithide');
    });


    $j(".next").bind("click",function() {
        carousel.next();
        currentTab+= 1;
        selectNavTab(currentTab);
        return false;
    });
    
    $j(".prev").bind("click",function() {
        carousel.prev();
        currentTab--;
        selectNavTab(currentTab);
        return false;
    });
    
     $j('.navbar li a').bind('click', function() {
         $j('.navbar li a').each(function(){$j(this).removeClass('focus')});
         $j(this).attr('class','focus');
         var index = jQuery.jcarousel.intval($j(this).attr('index'));
         currentTab = index - 1;
         carousel.scroll(index);
         return false;
     });
}
function selectNavTab(index){
    var count = 0;
    $j('.navbar li a').each(function(){
        if(index == count)
            $j(this).removeClass('focus').addClass('focus');
        else 
            $j(this).removeClass('focus');
        count++;   
    });
}
    

$j(document).ready(function () {
    
    
    $j("#home-tour").jcarousel(
    {
        scroll: 1,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    
    CE.init();
    
});
