/*Code by Laboratre*/

$(function() {
    $('.map').maphilight({ fade: false });
});

$(document).ready(function() {

    var col1 = $("#col1");
    var col2 = $("#col2");
    var col3 = $("#col3");
    posizione = $.cookie("PositionBox");

    if (posizione) {
        var array = posizione.split("-");
        htmltext1 = array[0];
        htmltext2 = array[1];
        htmltext3 = array[2];


        //COL 1
        if (htmltext1) {
            $.each(htmltext1.split(","), function(i, id) {
                //appending the element with the ID given id should move each element to the end of the 
                // list one after another, and at the end, the order should be restored.
                if (id) {
                    $("#" + id).appendTo(col1);
                }
            });
        }
        //COL 2
        if (htmltext2) {
            $.each(htmltext2.split(","), function(i, id) {
                //appending the element with the ID given id should move each element to the end of the 
                // list one after another, and at the end, the order should be restored.
                if (id) {
                    $("#" + id).appendTo(col2);
                }

            });
        }

        if (htmltext3) {
            //COL 3
            $.each(htmltext3.split(","), function(i, id) {
                //appending the element with the ID given id should move each element to the end of the 
                // list one after another, and at the end, the order should be restored.
                if (id) {
                    $("#" + id).appendTo(col3);
                }

            });
        }
    }

});




$(function() {/*
		$( "#content" ).sortable({
			placeholder:	'box-placeholder'
			, opacity: 0.6
			,	cursor:			'move'
			});*/
    $('.columnHome').sortable(
			{

			    accept: 'box',
			    connectWith: '.columnHome',
			    //helperclass: 'box-placeholder',
			    //activeclass: 'sortableactive',
			    //  hoverclass: 'sortablehover',
			    handle: 'div.itemHeader',
			    tolerance: 'pointer',
			    // placeholder:	'box-placeholder',
			    opacity: 0.6,
			    cursor: 'move',
			    cancel: '.lock',
			    /*onChange: function(ser) {
			    },*/

			    onStart: function() {

			        $.iAutoscroller.start(this, document.getElementsByTagName('body'));
			    },
			    update: function(event, ui) {
			        //salvo posizione blocchi su cookie
			        var result = $('#col1').sortable('toArray');
			        var result2 = $('#col2').sortable('toArray');
			        var result3 = $('#col3').sortable('toArray');

			        result = result + ' - ' + result2 + '-' + result3;
			        result = result.replace('boxFacebook', '')
			        $.cookie('PositionBox', result, { expires: 365 })
			    },
			    onStop: function() {
			        $.iAutoscroller.stop();
			    }
			}
		);
    $(".groupWrapper").disableSelection();

});





function openWin(url, Width, Height) {
    l = (screen.availWidth - Width) / 2;
    t = (screen.availHeight - Height) / 2;
    features = "toolbar=no";      // yes|no 
    features += ",location=no";    // yes|no 
    features += ",directories=no"; // yes|no 

    features += ",menubar=no";     // yes|no 
    features += ",scrollbars=yes"
    features += ",resizable=no"

    features += ",height=" + Height;
    features += ",width=" + Width
    features += ",left=" + l;
    features += ",top=" + t;

    //  window.open(link + "?path=" + path, '_blank', features)
    //   newwin = window.open(url, 'popup', '_blank', features);
    window.open(url, '_blank', features)
}
