$(document).ready(function () {
    menu();
    slider();
    initRotation();
    loginBox();
    thumbRollover();
    titleSwitcher();
    homeBoxRollover();
    logoClickThrough();
});

var run;
var slideLength;
var current = 0;
var speed = 5000;


function logoClickThrough() {
    $(".rotatorImageList img").click(function () {
        document.location.href = "/our-clients/synopsis-of-our-clients";
    });
}

function titleSwitcher() {
    var originalText = $('.changeable').html();

    $('.thumbs img').hover(function () {
        var src = $(this).attr("alt");

        if (src == "") { src = originalText; } // prevent empty space if alt tag value is empty //

        $('.changeable').html(src);
    },
    function () {
        $('.changeable').html(originalText);
    });
}

function thumbRollover() {

    $("img.a").hover(
function () {
    $(this).stop().animate({ "opacity": "0" }, "slow");
},
function () {
    $(this).stop().animate({ "opacity": "1" }, "slow");
});

}

function homeBoxRollover() {

    $(".slidebox").hover(
function () {
    var img = $(this).find('img.light');
    var Id = ($(this).attr('id')).split('-')[1];
    $(img).stop().animate({ "opacity": "0" }, "slow");
    $('#homeBox' + Id).stop().animate({ "opacity": "1" }, "slow");
},
function () {
    var img = $(this).find('img.light');
    var Id = ($(this).attr('id')).split('-')[1];
    $('#homeBox' + Id).stop().animate({ "opacity": "0" }, "slow");
    $(img).stop().animate({ "opacity": "1" }, "slow");
});

}



function loginBox(){
	$('.toggle').click(function() {
		$('.login').slideToggle(300);
	});
}
	
function initRotation(){
	slideLength = $('.slide').length; //count the number of slide

	run = setInterval('rotate()', speed);
}

function rotate(){
	current++; // reset current to next slide
	initFader(); // call the fader
}

function initFader(){
	clearInterval(run);
	$('.slide:last').fadeOut(800, function() {
		$('.slide:first').before($(".slide:last"));
	    $('.slide:first').fadeIn(0);
	    getSlideEq();
	    $('.sliderBtns li a').removeClass('active');
		$('.sliderBtns li').eq(current).find('a').addClass('active');
	    run = setInterval('rotate()', speed);
	});
}

function getSlideEq() {
	if(current > (slideLength - 1)){
		current = 0;
	}
	else if(current < 0)
	{
		current = (slideLength - 1);
	}
}

function slider(){ // sliding tabs on homepage boxes //
	
	$(".slidebox").hover(
	function(){ 
	var Id = ($(this).attr('id')).split('_')[1];
	
	$("#slideout"+Id).animate({left:"0"});
	},
		 
	function() {
	var Id = ($(this).attr('id')).split('_')[1];
	$("#slideout"+Id).animate({left:"-230"});
	
	});
	 
}


function menu(){
$(function(){

    $("ul.dropdown li").hover(function(){
     $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
     }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
});
}

