var resetHtml = false;
$(document).ready(function(){
	

/*********Show vertical line on hover top menu*************/
	$('.content .top-menu ul li').hover(function(){
		if (resetHtml == false){
			if ($(this).find('.popup-gallery').length > 0 ){
				$(this).find('.popup-gallery').show();
			}else{
				$(this).find('.no-popup-gallery').show();
			}
			$(this).parent().css('z-index','1');
			var name = $(this).attr('class');
			$(this).find('#name-hover').css('left', '0').find('a').html(name);
		}else{}
	},function(){
		if (resetHtml == false){
			if ($(this).find('.popup-gallery').length > 0 ){
				$(this).find('.popup-gallery').hide();
			}else{
				$(this).find('.no-popup-gallery').hide();
			}
			$(this).parent().css('z-index','2');
		}else{}
	})

/*********Show popup on click top menu*************/
	$('.content .top-menu ul li').click(function(){
		if ($(this).find('.popup-gallery').length > 0 ){
			if (resetHtml == false){	
				var popup = $(this).find('.popup-gallery');
				var link = $(this).find('a.link').attr('href');
				popup.css({
					'background': 'none',
					'width': '228px'
				});
				popup.parent().css('left', '-78px');
				if ($.browser.msie && $.browser.version == 6){
					popup.css({
						'filter': 'none'
					})
				}
				popup.load(link, function(){
					closePopup();
					return true;
				});
				popup.show();
				resetHtml = true;
				return false;
			}else{
				return false;
			}
		

		}		

	})
	
/*********Hover effects in IE6*************/	
	if ($.browser.msie && $.browser.version == 6){
		$('.content .bottom-grid ul.left-menu li').hover(function(){
			$(this).css('background', 'none');
			$(this).find('a').css({
				'background': '#9D9D90',
				'width': '178px',
				'position': 'relative'
			})
		},function(){
			$(this).css('background', '#A3A60F');
			$(this).find('a').css({
				'background': 'none',
				'filter': 'none'
			})
		})
		
		$('.content .bottom-grid ul.left-menu li.top').hover(function(){
			$(this).css('background', '#aaaa9a');
			$(this).find('a').css({'background': 'none', 'filter': 'none'});
		})
		
		$('.content .bottom-grid ul.left-menu li.last').hover(function(){
			$(this).find('a').css({
				'padding-top': '11px'
			})
		})
		
		$('.content .bottom-grid ul.left-menu li.active').hover(function(){
			
		}, function(){
			$(this).css('background', 'none');
			$(this).find('a').css({
				'background': 'none',
				'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="./public/images/bg/grey-opacity-line.png", sizingMethod="scale")',
				'width': '178px',
				'padding-top': '14px'
			})	
			
		})

	}
})


function closePopup(){
	
	/**Show element menu name in bottom of popup**/
	var name = $('#name').parent().parent().parent().attr('class');
	$('#name').html(name);
	
	/**Activate image gallery in popup**/	
	$(".photo-cont").jCarouselLite({
		btnNext: ".info .next",
		btnPrev: ".info .prev",
		visible: 1,
		circular: false
    });
	
	/*** Show count images in gallery***/
	var size = $('.photo-cont ul li').size();
	$('#size').html(size);
	
	/*** Onclick left/right, change number of current image***/
	$('.info .next, .info .prev').click(function(){
		setTimeout(imageNumber, 400);
	})
	
	/**	Close popup onclick close button **/
	$('a.close').click(function(){
		resetHtml = false;
		$(this).parent().parent().parent().parent().css('z-index', '2');
		$(this).parent().parent().parent().css({'left' : '-2px'});
		$(this).parent().parent().css({
			'background': 'url(./public/images/bg/popup-line.png) no-repeat',
			'width': '76px'
		});
		
		if ($.browser.msie && $.browser.version == 6){
			$(this).parent().parent().css({
				'background': 'none',
				'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="./public/images/bg/popup-line.png")'
			})
		}
		$(this).parent().parent().hide('');
		$(this).parent().parent().html('<div class="name" id="name-hover"></div>');
		return false;
	})
	
}
/*** Show number of current image in popup***/
function imageNumber(){ 
		var leftPos = $('.photo-cont ul').css('left');
		var currentImage = (parseInt(leftPos) / -185) + 1;
		currentImage = currentImage.toFixed();
		$('#curr').html(currentImage);
}
