$(document).ready(function(){
	$('#myGallery').galleryView({
		show_panels: true,
		show_filmstrip: false,
		
		panel_width: 644,
		panel_height: 269,
		frame_width: 10,
		frame_height: 10,
		
		start_frame: 1,
		filmstrip_size: 3,
		transition_speed: 1200,
		transition_interval: 8000,
		
		overlay_opacity: 1,
		frame_opacity: 0.3,
		
		pointer_size: 8,
		
		nav_theme: 'dark',
		easing: 'easeInOutQuad',
		
		filmstrip_position: 'bottom',
		overlay_position: 'bottom',
		
		panel_scale: 'nocrop',
		frame_scale: 'crop',
		
		frame_gap: 5,
		
		show_captions: false,
		fade_panels: true,
		pause_on_hover: true
	});
});

$(function() {
    $('.dragbox')
	.each(function() {
	    $(this).hover(function() {
	        $(this).find('h2').addClass('collapse');
	    }, function() {
	        $(this).find('h2').removeClass('collapse');
	    })
		.find('h2').hover(function() {
		    $(this).find('.configure').css('visibility', 'visible');
		}, function() {
		    $(this).find('.configure').css('visibility', 'hidden');
		})

		.end()
		.find('.configure').css('visibility', 'hidden');
	});

    $('.bt_close')
	.each(function() {
	    $(this).click(function() {
	        //$(this).parent('h2').parent('.dragbox').hide('slow'); //css('visibility', 'hidden')
	        $(this).parent('h2').parent('.dragbox').css('display', 'none');
	        updateWidgetData();
	    });
	});


    $('.column').sortable({
        connectWith: '.column',
        handle: 'h2',
        cursor: 'move',
        placeholder: 'placeholder',
        forcePlaceholderSize: true,
        opacity: 0.4,
        stop: function(event, ui) {
            /*$(ui.item).find('h2').click();
            var sortorder = '';
            $('.column').each(function() {
            var itemorder = $(this).sortable('toArray');
            var columnId = $(this).attr('id');
            sortorder += columnId + '=' + itemorder.toString() + '&';*/
            ui.item.css({ 'top': '0', 'left': '0' }); //Opera fix   
            if (!$.browser.mozilla && !$.browser.safari)
                updateWidgetData();

        }
        //alert(sortorder);
        //}
    })
	.disableSelection();

    // this initialises the demo scollpanes on the page.
    $('#pane1').jScrollPane({ showArrows: true, scrollbarWidth: 15, arrowSize: 16 });

});

function updateWidgetData() {
    var items = [];
    var cookieValue = '';
    var count = 0;
    $('.column').each(function() {
        var columnId = $(this).attr('id');
        $('.dragbox', this).each(function(i) {
            var collapsed = 0;
            if ($(this).css('display') == "none") {
                collapsed = 1;
            }
            //Create Item object for current panel   
            var item = {
                id: $(this).attr('id'),
                collapsed: collapsed,
                order: i,
                column: columnId
            };
            //Push item object into items array   
            //items.push(item);
            if (item.collapsed != 1) {
                var boxId = item.id;
                var index = boxId.lastIndexOf("_");
                boxId = boxId.substring(index + 1);
                cookieValue += (boxId + ",");
                count++;
            }

        });
        if (cookieValue[cookieValue.length - 1] == '&') {
            cookieValue += "0";
        }
        else {
            cookieValue = cookieValue.slice(0, cookieValue.length - 1);
        }
        cookieValue += '&';
    });
    cookieValue = cookieValue.slice(0, cookieValue.length - 1);
    if (count == 0) {
        cookieValue = "0&0&0";
    }
    //alert("cookie: "+cookieValue);
    createCookie('homePagePanelsCookie', cookieValue);
}

