﻿$(document).ready(function() {

/*Accordion__________________________________________*/
$("#nav p.menu_head").click(function()
{
    $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp(300);
    $(this).siblings();
 });
});


/*___ALARM DRAG___*/

/*$(function () {
    $("#alarmDrag").draggable({ handle: '#alarmStatus', cursor: 'move', scroll: false, axis: 'x', containment: [0, 0, 210, 0] });
});


/*Modal Window_________________________________________*/


$(document).ready(function () {

    $('a[name=modal]').click(function (e) {
        e.preventDefault();
        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //$('#mask').fadeIn(0);
        $('#mask').fadeTo("slow", 0.5);

        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        $(id).fadeIn(1000);
    });

    $('.window .close').click(function (e) {

        e.preventDefault();
        $('#mask, .window').hide();
        //document.getElementById("modalImage").src = "img/placeholderimg.jpg";
    });

    $('#mask').click(function () {

        $(this).hide();
        $('.window').hide();
        //document.getElementById("modalImage").src = "img/placeholderimg.jpg";
    });

});




/*Table DnD_____________________________________________*/

$(document).ready(setupDnD);

function setupDnD()
{
    try
    {
        // Initialise the table
        $('.draggableTable hr').addClass("nodrag nodrop");
        $(".draggableTable").tableDnD();

        $('.draggableTable').tableDnD({

            onDragStart: function (table, row) {
                $('.draggingMessage').remove();
                var rowLabel = $("td:first", row).text();
                
                $("td:first", row).prepend("<span class='draggingMessage'>Drop here</span>");
                $("body").append("<div class='draggingRow'>" + rowLabel + "</div>").mousemove(function (kmouse) {

                    $(".draggingRow").css({ left: kmouse.pageX + 5, top: kmouse.pageY + 5 });

                });

            },
            onDragClass: "myDragClass",

            onDrop: function (table, row) {

                makeHttpRequest(currentPage + "NewOrder=" + $.tableDnD.serialize(), "dropped", false);

                $('.draggingMessage').remove();
                $('.draggingRow').remove();
            }
        });
    }
    catch (err)
    {
    // do nothing
    }
};

/*tabbed content___________________________________*/


function showTab(tabId, panelId)
{
    $(".tabbedContent").hide();
    $("#" + tabId).addClass("activeTab").show();
    $("#" + panelId).show();

    // set click event handler onto LI tab elements
    $("ul.tabs li").click(selectTab);

};

function selectTab()
{
    $("ul.tabs li a").removeClass("activeTab");
    $(this).addClass("activeTab");
    $(".tabbedContent").hide();

    var active_Tab = $(this).find("a").addClass("activeTab").attr("href");
    $(active_Tab).fadeIn();
    makeHttpRequest(currentPage + "SelectTab=" + active_Tab.substr(1), "selectedTab", false);
    return false;
}

function selectedTab() { }


/*Menu Hover________________________________________*/



$(document).ready(function() {

  $('p.menu_head').hover(function() {
  
    $(this).toggleClass('menublue');
    
  })
  
  .click (function () {
     
  $('p.menu_head').not(this).removeClass('selected');      
  $(this).addClass('selected');
         
    });

});


/*Export_____________________________________________*/

$(document).ready(function () {


$('img.dropdownhead').click(function () {

$('ul.dropdownbody').slideToggle('fast');

});
});

/*addnew______________________________________________*/

$(document).ready(function () {

    $(".addnew").hide();

    $(".showaddnew").click(function () {
        $(this).next(".addnew").slideToggle(600);
    });
});



/*Select All__________________________________________*/
			
	function toggleChecked(status) {
	$(".select").each( function() {
	$(this).attr("checked",status);
	})
	}


/*Tooltip toggle______________________________________*/
	
		 $(document).ready(function() {
		 $('.tooltip').hide();
		
		   $('.tooltoggle').click( function() {
		    $('.tooltip').fadeToggle();
		    
		   });
		
		});


/*Message pop-up__________________________________________*/

/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/

this.textHover = function () {
    this.xOffset = -10;
    this.yOffset = 10;     

    $(".textHover").unbind().hover(
        function (e) {
            this.t = this.title;
            this.title = '';
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);

            $('body').append('<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>');

            $('p#vtip #vtipArrow').attr("src", 'img/vtip_arrow.png');
            $('p#vtip').css("top", this.top + "px").css("left", this.left + "px").fadeIn("slow");

        },
        function () {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    ).mousemove(
        function (e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);

            $("p#vtip").css("top", this.top + "px").css("left", this.left + "px");
        }
    );

};

jQuery(document).ready(function ($) { textHover(); }) 
