var speed = 25;
var snap = 1.5;
var snap_normal=1.5;
var snap_fast=15;
var scroll_width = 0;
var current_scroll = 0;

var fastSnap;


$(window).load(function(){
    
	initialize_scroll();
    
    
    $("#nav_left").mousedown(function(){
		snap = -(Math.abs(snap_fast));
    });
    
    $("#nav_right").mousedown(function(){
		snap = (Math.abs(snap_fast));
    });
    
    $("body").mouseup(function(){
		snap = snap > 0 ? (Math.abs(snap_normal)) : -(Math.abs(snap_normal));
    });
    
});

function initialize_scroll(){
    container_width = $(".scroller").innerWidth();
    content_width = 0;
    $(".scroller_inner").children().each(function(){
        content_width += $(this).outerWidth();
    });
    
	if(!content_width) return;
	
    scroll_width = content_width;
    
    html = $(".scroller_inner").html();
    $(".scroller_inner").append(html);
    $(".scroller_inner").append(html);
    
    if (container_width > content_width) {
        x = Math.floor(container_width / content_width)
        
		for (y = 1; y++; y <= x) {
            $(".scroller_inner").append(html);
        }
    }
    
    $(".scroller_inner").css('margin-left', -current_scroll);
    if($(".scroller_inner").html());
	anim = setInterval('scroll()', 1000 / speed);
}

function scroll(){
    current_scroll += snap;
    if (Math.abs(current_scroll) >= scroll_width) 
        current_scroll = 0;
    $(".scroller_inner").css('margin-left', -current_scroll - scroll_width);
}




$(function(){

    /*
     $("#logos").simplyScroll({
     autoMode: 'loop',
     speed: 1,
     pauseOnHover: false,
     frameRate: 20
     });
     */
    $(".phrases dt").click(function(){
        nextx = ($(this).next('dd').css('display') != 'none');
        if (nextx) {
            $(this).next('dd').stop(null, null).slideUp(300);
        }
        else {
            $(this).parent().find('dd:visible').stop(null, null).slideUp(300);
            $(this).next().slideDown(300);
        }
    });
    
    
    
    $(".ibswitch").click(function(){
        $(".ibswitch").removeClass('active');
        $(this).addClass('active');
        $(".theimage").removeClass('active');
        $("#" + $(this).attr('title')).addClass('active');
        $(".case_text").removeClass('active');
        $("#text_" + $(this).attr('title')).addClass('active');
    });
    
    
    
    $.fn.qtip.defaults = $.extend(true, {}, $.fn.qtip.defaults, {
        position: {
            my: "left center",
            at: 'right center',
            target: 'event',
            adjust: {
                x: -16,
                y: 0
            }
        },
        show: {},
        
        hide: {
            fixed: true
        }
    });
    
    $('.tooltip').each(function(){
    	 $(this).qtip({
        content: {
            text: $("#tooltip_" + $(this).attr('id')).html()
        },
        style: {
            classes: "qtip_buzz " + $(this).attr('rel')
        },
        position: {
            my: 'center left',
            at: 'center right',
            target: $("#buttons")
        }
    });
    });
   
    
    
    
    
});



$(window).load(function(){
    fit_menus();
    
    fit_footer();
    
    
});

$(window).resize(function(){
    fit_footer();
});



//Distribute menu elements to fit 100% width;
function fit_menus(){
    width = 756 - $("#main_menu").outerWidth();
    count = $("#main_menu li").size();
    pad = (width / count / 2);
    $("#main_menu a").each(function(){
        $(this).css('padding-left', parseInt($(this).css('padding-left')) + pad);
        $(this).css('padding-right', parseInt($(this).css('padding-right')) + pad);
    });
    $("#main_menu").show();
    
    
    width = $("#col_right").innerWidth() - 29 - $("#sub_menu").outerWidth();
    count = $("#sub_menu li").size();
    pad = (width / count / 2);
    $("#sub_menu a").each(function(){
        $(this).css('padding-left', parseInt($(this).css('padding-left')) + pad);
        $(this).css('padding-right', parseInt($(this).css('padding-right')) + pad);
    });
    $("#sub_menu").show();
}

function fit_footer(){
    wh = $(window).height();
    ch = $("#main_container").outerHeight();
    fh = $("#footer").outerHeight();
    
    if (wh > (ch + 200)) {
        $("#footer").outerHeight(wh - ch);
    }
}

