// ************* DEFINE CUFON TEXT REPLACMENTS
// Main menu links
Cufon.replace('a.mi', { hover:true, fontFamily: 'Univers bold con' });
Cufon.replace('a.mi-top', { hover:true, fontFamily: 'Univers con' });
//Cufon.replace('h1', { hover:true, fontFamily: 'Univers bold con' });

//Page content headings
//Cufon.replace('h1, h2, h3, h4, h5', { hover:true, fontFamily: 'Univers' });

// make jQuery no conflic with other APIs
var $j = jQuery.noConflict();


// extend jquery 
	$j.fn.wait = function(time, type) {
        time = time || 500;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $j(self).dequeue();
            }, time);
        });
    };


// ************* DEFINE jQuery functions
$j(document).ready(function(){

	// Define easing type
	jQuery.easing.def = 'easeOutSine';
	
	/*
		Add carousel functionality
	*/
    $j(".news-carousel").jCarouselLite({
    	scroll: 1,
    	visible: 1,
    	speed: 600,
    	start: 0,
        btnNext: ".next",
        btnPrev: ".prev"
    });
	
	/*
		Mark the active menu item
	
	var active = $j("li.menu-item-active")
  		active.addClass("hover-back");
  		active.css('height','41px');
		active.prev().css('height','41px');
		if(active.index() == 0) active.css('border-left-color','#cccccc');*/

	/*
		add events to menu-item
	*/
	$j("li.menu-item").hover(
		function () {
			/* mouse over */ set_mouse_over($j(this),true);
      	}, 
      	function () {
			/* mouse out */ set_mouse_out($j(this),true);
      	}
	);
	
	/*
		add events to menu-item-active
	*/
	$j("li.menu-item-active").hover(
		function () {
			/* mouse over */ set_mouse_over($j(this),true);
      	}, 
      	function () {
			/* mouse out */ set_mouse_out($j(this),true);
      	}
	);
	
	$j("li.submenu-item").click(function(event)
	{
		var sub = $j(this).parent('ul.novatel-submenu');
		sub.stop(true, true).slideUp("fast");
	});
	
	
	/*
		add events to subpage-item
	*/
	$j("li.subpage-item").hover(
		function () {
			/* mouse over */ $j(this).addClass("subpage-hover");
      	}, 
      	function () {
			/* mouse out */ $j(this).removeClass("subpage-hover");
      	}
	);
	
	
	// Track downloads with google analytics
	var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|msi|mp4|avi|wmv)$/i;
	$j('a').each(function(){
		var href = $j(this).attr('href');
		href = $j.trim(href);
		if (href.match(filetypes)){
			$j(this).click(function(event) {
				if(pageTracker) {
					var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
					pageTracker._trackEvent('Downloads', extension[0], href);
				}
			});
		}
	});
 
	
});

function set_mouse_over(e,css)
{
	/* open sub menu */
	var sub = e.find("ul.novatel-submenu");
	sub.stop(true, true).slideDown("normal");
	
	/* apply css if true */
	if(css == true) 
	{
		e.addClass("hover-back");
		e.css('height','40px');
		e.prev().css('height','40px');	
		if(e.index() == 0) e.css('border-left-color','#cccccc');
	}
};

function set_mouse_out(e,css)
{
	/* close sub menu */
	var sub = e.find("ul.novatel-submenu");
//	sub.stop(true, true).slideUp("fast");
        sub.stop(true, true).hide();
	
	/* apply css if true */
	if(css == true) 
	{
		e.removeClass("hover-back");
		e.css('height','25px');	
		e.prev().css('height','25px');	
		if(e.index() == 0) e.css('border-left-color','transparent');
		
		/*
		Don't need to have gradent background on active anymore
		e.removeClass("hover-back");
		if(!e.next().hasClass('menu-item-active')) e.css('height','25px');	
		if(!e.prev().hasClass('menu-item-active')) e.prev().css('height','25px');	
		if(e.index() == 0) e.css('border-left-color','transparent');
		*/
	}
};
	
	
	
	
	
	
	
	
	