﻿jQuery(document).ready(function(){
	ieHover("#nav li");
	//clearInputs();
	initGallery();
	initThumbs();
	initTabs();
})
function ieHover(_selector, _class){
	if(_class == null) _class = 'hover';
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		jQuery(_selector).each(function(){
			jQuery(this).mouseenter(function(){
				jQuery(this).addClass(_class)
			}).mouseleave(function(){
				jQuery(this).removeClass(_class)
			})
		})
	}
}
function initTabs(){
	jQuery('ul.tabset').each(function(){
		var _list = jQuery(this);
		var _links = _list.find('a.tab');

		_links.each(function() {
			var _link = jQuery(this);
			var _href = _link.attr('href');
			var _tab = jQuery(_href);

			if(_link.hasClass('active')) _tab.show();
			else _tab.hide();

			_link.click(function(){
				_links.filter('.active').each(function(){
					jQuery(jQuery(this).removeClass('active').attr('href')).hide();
				});
				_link.addClass('active');
				_tab.show();
				return false;
			});
		});
	});
}
function clearInputs(){
	jQuery('input:text, input:password, textarea').each(function(){
		var _el = jQuery(this);
		_el.data('val', _el.val());
		_el.bind('focus', function(){
			if(_el.val() == _el.data('val')) _el.val('');
		}).bind('blur', function(){
			if(_el.val() == '') _el.val(_el.data('val'));
		});
	});
}
function initGallery(){
	jQuery('div.fade-slide').each(function(){
		var set = jQuery(this);
		var slider = set.find('>ul');
		var item = slider.find('>li');
		var itemCoutn = item.length;
		var ind = 0;
		var animSpeed = 650;
		var switchTime = 7000;
		var timer;
		slider.css({
			width: set.width(),
			height: set.height(),
			position: 'relative'
		});
		item.css({
			position: 'absolute',
			top: 0,
			left: 0
		});
		item.hide().eq(ind).show();
		function nextSlide(){
			if(item.length > 1){
				if( ind < itemCoutn-1 ) ind++
				else ind = 0;
				if( $.browser.msie && $.browser.version == 8 ) item.hide().eq(ind).show()
				else item.fadeOut(animSpeed).eq(ind).fadeIn(animSpeed);
				if(timer){
					clearTimeout(timer)
					autoSlide();
				}
			}
		}
		function autoSlide(){
			timer = setTimeout( nextSlide, switchTime)
		}
		autoSlide();
		set.hover(
			function(){
				if(timer) clearTimeout(timer);
			},
			function(){
				if(timer){
					clearTimeout(timer)
					autoSlide();
				}
			}
		)
	});
}
function initThumbs(){
	jQuery('div.gallery-images').each(function(){
		var set = jQuery(this);
		var hold = set.find('div.holder');
		var slider = set.find('div.holder > ul');
		var slide = slider.find('>li');
		var switcher = set.find('ul.switcher');
		var link = switcher.find('>li');
		var animSpeed = 500;
		var ind = link.index(link.filter('.active:eq(0)'));
		if( ind == -1 ) ind = 0;
		var prevInd = ind;
		slider.css({
			width: hold.width(),
			height: hold.height(),
			position: 'relative'
		});
		slide.css({
			position: 'absolute',
			top: 0,
			left: 0
		});
		slide.hide().eq(ind).show();
		link.bind('click', function(){
			if( !jQuery(this).hasClass('active') ){
				ind = link.index(this);
				if( slide.eq(ind).length ){
					changeSlide();
					link.removeClass('active').eq(ind).addClass('active');
				}
			}
			return false;
		});
		function changeSlide(){
			slide.eq(prevInd).fadeOut(animSpeed);
			slide.eq(ind).fadeIn( animSpeed, function(){ prevInd = ind });
		}
	})
}

function geniustracker(){
	if (self==top){
		document.write("<scr" + "ipt type='text/javascript' language='JavaScript' id='GeniusCode' src='" + 'http://eghfi.rsvpgenius.com/mgTrack1.js?mgcid=d6dcgJW' + "'><\/scr" + "ipt>");
		}
}
