// Main JavaScript Init
$(document).ready(function(){
    
    initMenu();
    initNewsTicker();
    initToggle();
    initCarousel();
    
});

function initMenu() {
    //init dropdown nav
    $('#mainNav').dropDownMenu({timer: 500, parentMO: 'parent-hover', childMO: 'child-hover'});
};

function initCarousel() {
    // initialize blackberry Carousel
    $("div.carousel").scrollable({
    
        size: 6,
        clickable: true,
        activeClass: "selected",
        prev:      "a.prev",
        next:      "a.next"
    }); 
};

function initToggle() {
    //init "read more" content toggle
    $('h6.toggle').click(function() {
        $(this).next().toggle("normal");
        $(this).toggleClass('upArrow');
        return false;
    });
    
    //init FAQ toggle
    $('a.toggle').click(function() {
        $(this).next().toggle("normal");
        $(this).toggleClass('open');
        return false;
    });      
     
};


function getpage(page) {
    
    // page controller only returns content when requested from ajax        
    $.post('http://www.siprelay.com/' + page,{},function(data) {
        $('#subContentWrap').html(data);
        initToggle();
        initTabs();
        $('#video_chooser').hide(); //hide video chooser when using ajax'd content
    },'html');
    
    // last segment of URI is selected page    
    $.post('http://www.siprelay.com/template/secondary_nav/' + page,{},function(data) {
        $('#leftBar').html(data);
    },'html');
    
    // last segment of URI is selected page
    $.post('http://www.siprelay.com/template/header/' + page,{},function(data) {
        $('#header').html(data);
        initMenu();
    },'html');
    
};


function getheader(page) {

    // last segment of URI is selected page
    $.post('http://www.siprelay.com/template/header/' + page,{},function(data) {
        $('#header').html(data);
        initMenu();
    },'html');
    
};

function initNewsTicker() {
    // init scrollable  
    
    if($.browser.msie && $.browser.version < 7) {
        //no alpha effects for ie6
        
        $("div.latestNews").scrollable({
            vertical: true,  
            size: 1,
            loop: true,
            speed: 600
        }).autoscroll({
            autoplay: true,
            steps: 1,
            interval: 4000
        });
        
    } else {
        
        $("div.latestNews").scrollable({
            vertical: true,  
            size: 1,
            loop: true,
            speed: 600,
            onBeforeSeek: function() { this.getItems().fadeTo(150, 0.2); },
            onSeek: function() { this.getItems().fadeTo(150, 1); }
        }).autoscroll({
            autoplay: true,
            steps: 1,
            interval: 4000
        });
        
    }
};  


function submitSearch() {
    document.forms["search_form"].submit();
}



function clearField(tF) {
    if(tF.defaultValue == tF.value) {
        tF.value = ""; tF.style.color = "black";
    }
}



function selectShow(select, trigger, element) {
    $(select).change(function() {
        $(element).css("display", ($(this).val() == trigger) ? 'block' : 'none');
    });
    //fire change event in case trigger is default value
    $(select).trigger("change");

}


