var tmp_negeso_menu_item_to_close = null;

function checkHover() {
	var $=jQuery;
	if (tmp_negeso_menu_item_to_close) {
		tmp_negeso_menu_item_to_close
			.removeClass('item_over item_first_over item_last_over item_single_over')
			.find('li')
			.removeClass('item_over item_first_over item_last_over item_single_over');
		// Hiding ULs in reverse order - special for IE. Try to change to tmp_negeso_menu_item_to_close.find('ul').hide() and see what it will be in the IE
		var uls=tmp_negeso_menu_item_to_close.find('ul').get();
		for (var i=0; i<uls.length; i++)
			$(uls[uls.length-1-i]).hide(); //.fadeOut('fast');
		tmp_negeso_menu_item_to_close = null;
	} //if
} //checkHover

function negesoMenu(ul_id) {
	var $=jQuery;
	//if (ul_id == 'site_menu')	positiontLi();
	$('#'+ul_id+' li').hover(
		function() {
			checkHover();
			if ($(this).hasClass('item_first') || $(this).hasClass('item_first_selected')) $(this).addClass('item_first_over');
			else if ($(this).hasClass('item_last') || $(this).hasClass('item_last_selected')) $(this).addClass('item_last_over');
			else if ($(this).hasClass('item_single') || $(this).hasClass('item_single_selected')) $(this).addClass('item_single_over');
			else $(this).addClass('item_over');
			$(this).find('> ul').show();//slideDown('fast');
		}, 
		function() {
			tmp_negeso_menu_item_to_close = $(this);
			setTimeout("checkHover()",300);
		}
	).each(function(i,o){
		var anchor;
		if (anchor=$(this).find('> a').get(0)) {
			o.onclick=function(e){var ev=e||window.event||window.e; ev.cancelBubble=true; window.location.href=$(anchor).attr("href")};
			anchor.onclick=function(){return false;}
		} else {
			o.onclick=function(e){var ev=e||window.event||window.e; ev.cancelBubble=true;}
			$(o).css({'cursor':'default'});
		}
	})
}

function positiontLi(){
	var li = $('#site_menu > li');
	var ulWidth = 0;
	for (var i=0; i<li.length; i++){
		ulWidth = li[i].offsetWidth + 34 + ulWidth;
	}	
	$("#site_menu").css("width",ulWidth+'px');	
}

/*function closePopup(className){
	$('.'+className).slideUp("slow");
}*/

$(document).ready(function(){	
	$('.newsPopup').slideToggle("slow");
})
function showPopup(){
	$('.newsPopup').slideToggle("slow");
}

function closeNewsPopup(){
	$('.newsPopup').slideUp("slow");
}


var dialog_collection = $('<DIV id="popup_collection" title=""></DIV>');
var dialog_lookbook = $('<DIV id="popup_lookbook" title=""></DIV>');
var dialog_company = $('<DIV id="popup_company" title=""></DIV>');
$(document).ready(function(){	
	$(dialog_collection).append($('#popup_collection').clone(true));
	$(dialog_lookbook).append($('#popup_lookbook').clone(true));
	$(dialog_company).append($('#popup_company').clone(true));
	$('*.open_popup_collection').click(function(e){
		popupBannerOnLoad(dialog_collection,'collection');
		return false;
	})
	$('*.open_popup_lookbook').click(function(e){
		popupBannerOnLoad(dialog_lookbook,'lookbook');
		return false;
	})
	$('*.open_popup_company').click(function(e){
		popupBannerOnLoad(dialog_company,'company');
		return false;
	})
})

function popupBannerOnLoad(dialog,id){
	var $=jQuery;
	var height = $('#popup_'+id).height();
	var topDiv = Math.round(parseFloat(document.body.clientHeight/2)-parseFloat(height/2)-60);
	if (topDiv<0) topDiv = 10;
	if($('#popup_'+id,dialog)[0]){
		$(dialog).dialog({
			bgiframe: true,
			width: 685,
			height: height,
			position: ['center',topDiv],
			modal: true,
			dialogClass: 'popupBlock',
			open: function(){
				var dialog = this;
				$('#popup_'+id, dialog).css({'visibility':'visible','top':'0','left':'20px'});
			},
			close: function() {
				$(this).remove();
			}
		});
	}
}