/*--- fade gallery function ---*/
function initGall(){
	var _infotext = $('.image-box ul > li');
	var _gallnav = $('.img-list > li');
	var _a = _gallnav.index(_gallnav.filter('.active:eq(0)'));
	var _speed = 400;
	if(_a == -1) _a = 0;
	var _flag = 0;
	function gallFade(){
		if(_flag){
			_gallnav.css('opacity',0.75).removeClass('active').eq(_a).addClass('active').css('opacity', 1);
			_infotext.fadeOut(_speed).eq(_a).fadeIn(_speed);
		}else{
			_gallnav.not('.active').css('opacity',0.75);
			_infotext.hide().eq(_a).show();
		}
		_flag = 'true';
	};
	gallFade();
	_gallnav.click(function(){
		_a = _gallnav.index($(this));
		gallFade();
		return false;
	});
}
/*--- IE6 hover ---*/
function ieHover(h_list){
	if ($.browser.msie && $.browser.version < 7){
		$(h_list).hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
	}
}
/*--- document ready ---*/
$(document).ready(function(){
	ieHover('ul.nav > li');
	initGall();

	getTestimonials();
	initNavigationDropdowns();
	initMenu();
});

function getTestimonials(){
	$('.cite-block .frame').load('/inc/testimonials.shtml blockquote:random');
}

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;
    }
});

var menu;
var path = window.location.pathname;

function initNavigationDropdowns(){
	menu = $('.sub-nav ul, .nav-area ul');
	$('li > span > a', menu).each(function(){
		if($(this).attr('href').replace(/(\/$)|(.shtml)/,'')==path.replace(/(\/$)|(.shtml)/,'') || $(this).attr('href').replace(/(\/$)|(.shtml)/,'')==path.replace(/\/[^\/]+.shtml/,'') || $(this).attr('href').replace(/(\/$)|(.shtml)/,'')==path.replace(/\/[^\/]+\/[^\/]+.shtml/,'')){
			$(this).parents('li').addClass('active');
		}
	});	
}

function MM_jumpMenuGo(objId,targ,restore){ 
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}

function initMenu(){
	var menuTopLevel = $('ul#top-level');
	var marginLeft = ($(menuTopLevel).parent().width() - $(menuTopLevel).width())/2;
	$(menuTopLevel).css({'margin-left':marginLeft+'px'});
	
	if ($('ul#top-level > li.active').length == 0) {
		$('ul#top-level > li:eq(0)').addClass('active');
	}
}
