function resetDrop(nav, width){
	alert(width);
	nav.css({width: width});
	alert(nav.width);
}
$(function(){
   initGall();
   initPhotoHeader();
   initTooltips();
});
/*--- photo header ---*/
function initPhotoHeader(){
	var width = 0;
	$('#nav li').hover(
		function(){
			if($('.drop', this).length > 0){
				var nav = $('.drop', this);
				width = width == 0 ? nav.outerWidth() : width;
				nav.stop().css({width:0, overflow: 'hidden'}).show().animate({width: width});
			}
		},
		function(){
			if($('.drop', this).length > 0){
				var nav = $('.drop', this);
				nav.stop().animate({width:0});
			}
		}
	);

	if($('#photo-header').length>0)
		$('#photo-header').galleryView({
			panel_width: 890,
			panel_height: 293,
			border: 'none',
			nav_theme: 'light',
			transition_speed: 1200
	 });

}
/*--- gallery function ---*/
function initGall(){	
	$('.carousel').each(function(){
		var _duration = 10000;
		var _hold = $(this).children('div');
		var _list = _hold.children();
		var hold_w = _hold.width();
		var list_w = 0;
		var _d = 0;
		var _flag = true;
		var _el = _list.children().each(function(){
			list_w += $(this).outerWidth();
		});
		_step = hold_w;
		var _m = list_w;
		
		if(list_w > hold_w){
			
			var t_a = _list.find('a').index(_list.find('a.active:eq(0)'));
			if(t_a != -1){
				t_a = _list.find('a').eq(t_a).position().left;
				_flag = false;
			}
			_list.append(_el.clone(true)).append(_el.clone(true)).css('left', -list_w);
			if(t_a != -1){
				_list.css('left', -(list_w+t_a));
			}
			$(this).children('.btn-prev').click(function(){
				_flag = false;
				_duration = 1000;
				_list.stop();
				listMove(-1.11);
				return false;
			});
			$(this).children('.btn-next').click(function(){
				_flag = false;
				_duration = 1000;
				_list.stop();
				listMove(1.11);
				return false;
			});
			if(_flag) listMove(1.11);
		}
		else{
			$(this).children('.btn-prev').click(function(){
				return false;
			});
			$(this).children('.btn-next').click(function(){
				return false;
			});
		}
		function listMove(_f){
			_m = -parseInt(_list.css('left'));
			if(_f == 1.11){
				if(_m + _step >= 3*list_w - hold_w){
					_m -= list_w;
					_list.css('left', -_m);
				}
				_m += _step;
			}
			else if(_f == -1.11){
				if(_m < _step){
					_m += list_w;
					_list.css('left', -_m);
				}
				_m -= _step;
			}
			else{
				if(_m + _step >= 3*list_w - hold_w){
					_m -= list_w;
					_f -= list_w;
					_list.css('left', -_m);
				}
				_m = _f;
			}
			liWidth = _list.find('li').eq(0).outerWidth();
			_m = Math.round(_m/liWidth)*liWidth;
			_list.animate({left: -_m}, _duration, 'linear', function(){
				if(_flag) listMove(1.11);
			});
		}
	});
}
function initTooltips(){
	var _hold = $('.text-block');
	var title = '';
	$('img', _hold).hover(
		function(event){
			if(this.title != ''){
				var leftPos = event.pageX + 10;
				var TopPos = event.pageY + 10;
				var tooltip = $('body').append('<div class="tooltip">' + this.title + '</div>');
				$('div:last').hide().css({position:'absolute', left:leftPos+'px', top:TopPos+'px'}).fadeIn('fast');
				title = this.title;
				this.title = '';
			}
		},
		function(){
			$('div.tooltip:last').remove();
			this.title = title;
			title = '';
		}
	);
}

