function initTabsFade(){
	$('div#tabs-wrapper').each(function(){
		var hold = $(this);
		var links = hold.find('a.tab');
		var tabs = hold.find('div.tab-contnet');
		var current2 = $('div.tab-contnert-visible');
		var current2_H = current2.outerHeight(true);
		var _active;
		var _tabH = [];
		var speed = 700;
		
		links.each(function() {
				current2.show();
		});
		links.click(function(){
			links.removeClass('active');
			$(this).addClass('active');
			var current = $($(this).attr('rel'));
			var _i = links.index($(this));
			tabs.hide();
			current.show();
			hideFlash();
		});
	});
}

jQuery.fn.animationNav = function(_options){
	if($.browser.msie && $.browser.version < 7){
		$('tabset li').eq(0).addClass('first-child');
	}
    // defaults options	
    var _options = jQuery.extend({
	    duration:300,
	    addBG:'<li class="bg"><a href="#"><span>&nbsp;</span></a></li>',
	    bgClass :'bg',
		animEffect: 'linear'
    },_options);

    return this.each(function(){
	    var _obg = jQuery(this);
	    var _liWidth = [];
	    var _aWidth = [];
	    var _lis = jQuery(_obg).children('li');
	    var _links = jQuery(_obg).find('a');
	    var _linkIndex = _links.index(_links.filter('.active'));
	    var _timer = false;
	    var _pLeft = parseInt(jQuery(_obg).css('paddingLeft'))+1;
	    var _visible = false;
	    
	    _lis.each(function(i, el){
			_liWidth[i] = jQuery(el).outerWidth(true);
			_aWidth[i] = jQuery(el).width();
	    });
	    if (jQuery.browser.msie) jQuery(_options.addBG).insertBefore(jQuery(_obg).find('li:first-child'));
	    else jQuery(_obg).append(_options.addBG);
	    		
	    jQuery.fn.animationNav.animateThis = function(_activeIndex, _obg){
			var _activeLiWidth = _liWidth[_activeIndex];
			var _activeAWidth = _aWidth[_activeIndex];
			var _left = _pLeft;
			for (var j = _activeIndex-1; j >= 0; j--) {
				_left += _liWidth[j];
			}
			$('li.bg', _obg)
				.stop()
				.animate({width:_activeAWidth +'px'},{queue:false,duration:150, easing:'linear'})
				.animate({
					left:_left+'px'
				},{queue:false,duration:_options.duration, easing:_options.animEffect});
			_left = _pLeft;
	    }
	    jQuery.fn.animationNav.showThis = function(_activeIndex, _obg){
			var _activeLiWidth = _liWidth[_activeIndex];
			var _activeAWidth = _aWidth[_activeIndex];
			var _left = _pLeft;
			for (var j = _activeIndex-1; j >= 0; j--) {
				_left += _liWidth[j];
			}
			$('li.bg', _obg)
				.css({
					left:(_left+(_activeAWidth/2))+'px',
					display: 'block'
				})
				.animate({
					width:_activeAWidth +'px',
					left:_left+'px'
				},{queue:false,duration:_options.duration, easing:_options.animEffect});
			_left = _pLeft;
	    }
	    jQuery.fn.animationNav.hideThis = function(_activeIndex, _obg){
			var _activeAWidth = _aWidth[_activeIndex];
			var _left = parseInt($('li.bg', _obg).css('left'));
	    }
	    
	    if (_lis.filter('.active').length) {
	    	var _lisIndex = _lis.index(_lis.filter('.active'));
			jQuery.fn.animationNav.animateThis(_lisIndex, _obg);
	    } else {
			jQuery(_obg).children('.'+_options.bgClass).css('display','none');
	    }
    
	    _links.click(function(){
			_linkIndex = _links.index(jQuery(this));
			if (_timer) clearTimeout(_timer);
			if (_lis.filter('.active').length || _visible) {
				jQuery.fn.animationNav.animateThis(_linkIndex, _obg);
			} else {
				jQuery.fn.animationNav.showThis(_linkIndex, _obg);
				_visible = true;
			}
	    }, function() {
			var _this = this;
			_timer = setTimeout(function() {
					var _linksIndex = _links.index($(_this));
					jQuery.fn.animationNav.hideThis(_linksIndex, _obg);
					_visible = false;
			}, 800);
	    });
	    
    });
}

$(document).ready(function(){
	initTabsFade();
	$('ul.tabset').animationNav();
	prepDrops();
});
	
function hideFlash()
{

}

function showFlash(force)
{
  var ver = 2;
  if (force || (ver > $.cookie('hf'))) {
    $.cookie('hf', ver);

    $("#tab1 .tab-holder").html('<div id="home-flash"></div>');
    swfobject.embedSWF("assets/home_flash.swf", "home-flash", "900", "295", "9.0.0","flash/expressInstall.swf", flashvars, params, attributes);
  } else {
    hideFlash();
  }
}

function prepDrops()
{
	$("#tabs select").uniform();
	$('.chooseLocation').change(function(){
		if ($(this).val() != '')
		{
			$(this).parent().parent().parent().submit();
		}
	});
}
