function hideElement(divId)
{
	$('#' + divId).hide();	
}

	
function cloudShow(e) {
	var cloudy = $('#cloud_icons');

	var target = e.currentTarget;
	var x = $(target).offset().left + $(target).width() + 6;
	var y = $(target).offset().top + $(target).height() / 4;
	
	cloudy.css("left", x );
	cloudy.css("top",  y );
	
	contentElement = $(this).next("div.product_data");
	//jesli element z contentem nie jest sąsiadem to poszukiwanie o poziom wyżej...
	// jest to sytuacja <a><img /></a>
	if( contentElement.length < 1 ){
		contentElement = $(this).parent().next("div.product_data");
	}	
	cloudy.find("div.cloud_content").html( contentElement.html() );
	cloudy.show();
	cloudy.find('.cloud_body').equalHeights();
	refresh_clouds();
	
	$(this).mouseout( function () { 
		cloudy.hide() 
	});
}

function refresh_clouds(){
	$('.cloud').each ( function () {
		$(this).find('.cloud_top').css('width', $(this).find('.cloud_content').css('width'));
		$(this).find('.cloud_bottom').css('width', $(this).find('.cloud_content').css('width'));						 
	});
}


function cloudHide(){
	$('#cloud_icons').hide()
}


$(document).ready( function() {
	
	$('#content').equalHeights();	
	
		
	$('#main_menu div').click( function () {
		window.location = $(this).find('a').attr('href');
	});
	
	$('.cloud').mouseleave( function () {
		$(this).hide();
	});
	$('.cloud_nohide').unbind("mouseleave");
	
	$('div.folder').click(function () {
		var parent = $(this).parent();
		if(parent.hasClass('fold'))
		{
			parent.find("ul").show();
			parent.removeClass('fold');
			parent.addClass('unfold');
		}
		else if(parent.hasClass('unfold'))
		{
			parent.find("ul").hide();
			parent.removeClass('unfold');
			parent.addClass('fold');
		}
										 
										 
	});
	
	$('.search_submit').click( function () {
			$(this).prev("form").submit();							
	});
	
	
	$('#icons div.image img, .icons div.image img').mouseover( 
		cloudShow
	);
	
	
	
	$('#icons div.image img').mouseout( cloudHide );
	
	$("a.noclick").click ( function () { return false });
	
	$("#product_details div.mini_images img").click ( function () {
		$(this).parents("div.mini_images").prev("div.main_image").html( $("<img/>").attr("src", $(this).parent("a").attr("href")) );
		$("#product_details div.mini_images img").removeClass("active");
		$(this).addClass("active");
	});
	
	$("ul.toggle li").click ( function () {
		$('div.' + $(this).parent().attr("id")).hide();
		$(this).parent().find("li.active").removeClass("active");
		$(this).addClass("active");
		$("#" + $(this).find("a").attr("name")).show();
	});
	
	$('.overunderline').mouseover ( function () {
		$(this).addClass('underline');										  
	});
	
	$('.overunderline').mouseleave ( function () {
		$(this).removeClass('underline');										  
	});
	
	$(document).click( function () {
		$('#right_bar').css("min-height", 0);
		$('#main').css("min-height", 0);	
		$('#content').equalHeights();								   
	});
	
	refresh_clouds();	
	$('.cloud_body').equalHeights();
	
	window.onload = function () {
		$('#right_bar').css("min-height", 0);
		$('#main').css("min-height", 0);	
		$('#content').equalHeights();	
	};
	
});