// JavaScript Document

var menu;
var path = window.location.pathname;

$(document).ready(
	function(){
		logoLinkUpdate();
		initNavigationDropdowns();
		getTestimonials();
		initPricingDropDown();
	}			 
);


function logoLinkUpdate(){
	if(path=='' || path=='/'){
		$('#logo img').unwrap();
	}
}

function initNavigationDropdowns(){
	menu = $('#navigation');
	
	$('li>a', menu).each(function(){
		if($(this).attr('href').replace(/(\/$)|(.shtml)/,'')==path.replace(/(\/$)|(.shtml)/,'')
			|| $(this).attr('href').replace(/(\/$)|(.shtml)/,'')==path.replace(/\/[^\/]+.shtml/,'')
			){
				$(this).parents('#navigation li').addClass('selected');
		}
	});
	
	hideNavigationDropdowns();
	
	$('li.dropdown', menu)
		.bind('mouseenter', function(){
			showNavigationDropdown(this);
		}).bind('mouseleave', function(){
			hideNavigationDropdowns();
	});
		
	
}

function showNavigationDropdown(el){
	if($('li.dropdown.selected', menu).length>0 && !$(el).hasClass('selected')){
		$('li.dropdown.selected ul', menu).fadeOut(100);
	}
	$('li.dropdown>a', menu).stop(true, true);
	$('a:first', $(el)).stop(true, true).animate({paddingBottom: '4px'}, 100);
	
	$('#sub-navigation').stop(true, true).slideDown(100);
	$('ul', $(el)).stop(true, true).fadeIn(300);
}

function hideNavigationDropdowns(){
	$('li.dropdown:not(.selected) ul:visible', menu).stop(true, true).fadeOut(100);
	$('li.dropdown:not(.selected)>a', menu).stop(true, true).animate({paddingBottom: '0px'}, 200);

	if($('li.dropdown.selected', menu).length>0){
		showNavigationDropdown($('li.dropdown.selected', menu));
	} else {
		$('#sub-navigation').stop(true, true).slideUp(300);
	}
}

//Testimonials AJAX download and randow display
function getTestimonials(){
	$('#testimonials').load('http://www.digilabspro.com/testimonials.shtml dl:random');
}


//Pricing table switcher
function initPricingDropDown(){
	$('.pricing-button').click (function(){
		$('.pricing-table-div').slideToggle('slow'); 
		$('.pricing-button').toggleClass ('button-up');
		$('.pricing-button').toggleClass ('button-down');
		return false;
	});
}


//// JQuery extentions 

jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});