﻿$(function(){
	
//HOVER BLOCKS
$(".portlet").hover(
	function(){
		$(".portlet").find(".individualBlock").css({"margin": "0px"});
		$(".portlet").removeClass("portletHover").find(".dragBlock").hide(0);
		var portlet = $(this);
		portlet.find(".individualBlock").css({"margin": "-5px"});
		portlet.addClass("portletHover").css("border-color", portlet.find(".move").css("color")).find(".dragBlock").show(0);
	},
	function(){
		var portlet = $(this);
		portlet.find(".individualBlock").css({"margin": "0px"});
		portlet.removeClass("portletHover").find(".dragBlock").hide(0);
	}
);

//SORT BLOCKS
$(".sortable").sortable({
	items: ".portlet",
	connectWith: [".sortable"],
	cursor: "move",
	forcePlaceholderSize: true,
	handle: ".move",
	placeholder: "giftContainer",
	revert: true,
	scroll: false,
	tolerance: 'pointer',
	start: function(event, ui){
		//config placeholder
		var verticalCenter = (ui.item.height()-178)/2;
		ui.placeholder.height(ui.item.height()+10).append('<div class="imgPrize" style="margin-top:'+ verticalCenter +'px"></div><div class="giftContainerBottom"></div>');
		//get highest column
		var highestCol = Math.max($('.leftContainer').height(), $('.centerContainer').height(), $('.rightContainer').height());
		$('.sortable').height(highestCol);
		/*
		$.ajax({
			type: "POST",
			url: "../",
			data: "&id="+ui.item.attr("id"),
			success: function(data, textStatus){
				if(data.length){
					$(".giftContainerBottom").css({"background":"none"});
					ui.placeholder.css({"background":"none"}).append(data);
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert(textStatus + " " + errorThrown);
			}
		});
		*/
	},
	stop: function(event, ui){
		var highestCol = Math.max($('.leftContainer').find(".heightContainer").height(), $('.centerContainer').find(".heightContainer").height(), $('.rightContainer').find(".heightContainer").height());
		$('.sortable').height(highestCol);
	}
});


});



