
// Navigation Bar Init 
function init_nav_bar() {
	$("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag

	$("#topnav li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
		$(this).find("span").show().html(linkText); //Add the text in the <span> tag
	}); 

	$("#topnav li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({
			marginTop: "-40" //Find the <span> tag and move it up 40 pixels
		}, 250);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0"  //Move the <span> back to its original state (0px)
		}, 250);
	});
}

// Called OnLoad
$(function() {
	
	// JQuerry Buttons Set Style
	$( "input:submit, a, button", ".Button" ).button();
	
	// Navigation Bar Init
	init_nav_bar();
	
	// Data Tables Settings
	$('.dataTable').dataTable( {
		"aaSorting": [[ 0, "desc" ]],
		"bJQueryUI": true,
		"aLengthMenu": [[5, 10, 20, -1], [5, 10, 20, "All"]],
		"iDisplayLength": 5,
		"sPaginationType": "full_numbers",

		"sDom": '<"H"lTfr>t<"F"ip>',
		"oTableTools": {
			"sSwfPath": "/static/swf/copy_cvs_xls_pdf.swf",
			"aButtons": [
				"copy", /*"csv", "xls", "pdf",*/
				{
					"sExtends":    "collection",
					"sButtonText": "Save",
					"aButtons":    [ "csv", "xls", "pdf" ]
				}
			]
		}
	} );

	// New
		$('.SetToggleOpened').click(function() {
			$(this).next().toggle('slow');
			return false;
		});//.next().hide();

    $('.SetToggleClosed').click(function() {
   		$(this).next().toggle('slow');
   		return false;
   	}).next().hide();

/*	$('.Box').draggable();*/
//	$('.Sortable').sortable();

	$("#sortableLeft").sortable({
			revert: true
		});
		
	$("#draggableLeft").draggable({
			connectToSortable: "#sortableLeft",
			helper: "clone",
			revert: "invalid"
		});
//	$( "ul, li" ).disableSelection();

	$("#saveBoxesButton").bind('click', function() {
		str = ''
		$("#sortableLeft > div").each(function(index) {
			if(this.id == '')
			{
//				$(this).children().children().eq(1).children().css("border","3px solid red")
//				alert( $(this).children().children().eq(1).children().val() );
				str += 'New:' + $(this).children().children().eq(1).children().val()
			}
			else
			{
				str += this.id
			}
			str += ','
		});
		$(this).val(str)
    });
	
	$('.DeleteBoxButton').button({
		icons: {
			primary: "ui-icon-trash"
		},
		text: false
    });

/*    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode",
        width: 600
    });*/

	$('.EditWidgetButton').button({
		icons: {
			primary: "ui-icon-image"
		},
		text: false
	}); /*.bind('click', function() {
        $.get('/dialog/editbox/'+this.id, function(data) {
            $( "#dialog" ).html(data);
            $( "#dialog" ).dialog( "open" );
        });
        return false;
	});*/

    $("#slider").easySlider({
   		auto: true,
   		continuous: true,
        numeric: true
   	});
});

