(function($) {
$(document).ready(function(){

	// CAROUSEL
	jQuery.fn.gallSlide = function(_options){
		var _options = jQuery.extend({
			duration: 900,
			autoSlide: 5000
		},_options);
	
		return this.each(function(){
			var _hold = $(this);
			var _speed = _options.duration;
			var _timer = _options.autoSlide;
			var _wrap = _hold.find('#slider ul');
			var _el = _hold.find('#slider ul > li');
			var _first = _el.index(_el.filter(':first'));
			var _count = _el.index(_el.filter(':last'));
			var _thumbs = _hold.find('.slider-nav li');
			var _w = 0, _wst = 0;
			var _wrapHolderW = _wrap.parent().width();
			var _t;
			var vid = 0;
			var _active = vid;
			var stop = false;
			
			function sum(){
				_w = 0;
				_el.each(function(_i){
					if (_i<=_active) _w += $(this).outerWidth(true);
				});
			}
			
			_el.each(function(_i){
				if (_i<=vid) _wst += $(this).outerWidth(true);
			});
			
			function scrollEl(){
				_wrap.eq(0).animate({
					marginLeft: -(_w - _wst) + "px"
				}, {queue:false, duration: _speed});
				
				$(_thumbs).removeClass("active");
				$(_thumbs).eq(_active).addClass("active");
			}
			function runTimer(){
				_t = setInterval(function(){
					_active++;
					if (_active > _count) _active = vid;
					sum();
					scrollEl();
				}, _timer);
			}
			$(_thumbs).each(function(id, el) {
				$(el).click(function()	{
					_active = id;
					sum();
					scrollEl();
				});
			});
			$(_hold).mouseenter(function(){
				if(_t) clearTimeout(_t);
				stop = true;
			})
			$(_hold).mouseleave(function(){
				runTimer();
				stop = false;
			});
			$("a.next").click(function(){
				_active++;
				if (_active > _count) _active = vid;
				sum();
				scrollEl();
				return false;
			});
			$("a.back").click(function(){
				_active--;
				if (_active < _first) _active = _count;
				sum();
				scrollEl();
				return false;
			});
	
			runTimer();
		});
	}

	// NAV
	//cache nav  
    var nav = $("#navigation");
    //add indicators and hovers to submenu parents  
    nav.find("li").each(function() {  
    
    
        if ($(this).find("ul").length > 0) {  

            //show subnav on hover  
            $(this).mouseenter(function() {  
                $(this).find("ul").stop(true, true).slideDown(120);  
                $(this).toggleClass("active");
            });  

            //hide submenus on exit  
            $(this).mouseleave(function() {  
                $(this).find("ul").stop(true, true).slideUp(120);
                $(this).toggleClass("active");
            });  
        }  
    
    
    });

});
})(jQuery);



jQuery(function($){
$('#slideshow').gallSlide({
		duration: 700,
		autoSlide: 7000
	});
	///
	$('.blink').focus(function () {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		})
	$('.blink').blur(function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr('title'));
			}
		})	
	$('.slider-nav a').live('click',function() {
		return false;
	});
	
});
