jQuery(function ($, undefined) {

    var $document = $(document);
    var $window = $(window);
    var $body = $(document.body);

    var rtl = ($body.css('direction') == 'rtl');

    function makeMouseHandlers(selectedClass) {
        return {
            mouseenter: function() {
                var $this = $(this);
                var $menu = $this.offsetParent();

                var $firstA = $this.find('a:first');
                var $firstDiv = $this.find('div:first');

                var pos = $firstA.position();
                
                var menuWidth = $menu.outerWidth(true);
                var popupWidth = $firstDiv.outerWidth(true);

                pos.top += $firstA.outerHeight(true);

                $firstA.addClass(selectedClass);
                $firstDiv.css({
                    position: 'absolute',
                    display: 'block'
                });

                if (rtl) {
                    var right = menuWidth - pos.left - $this.outerWidth(true);

                    if (right + popupWidth > menuWidth) {
                        right = menuWidth - popupWidth;
                    }

                    $firstDiv.css({
                        top: pos.top,
                        right: right
                    });
                }
                else {
                    if (pos.left + popupWidth > menuWidth) {
                        pos.left = menuWidth - popupWidth;
                    }

                    $firstDiv.css(pos);
                }
            },

            mouseleave: function() {
                var $this = $(this);

                $this.find('div:first').hide();
                $this.find('a:first').removeClass(selectedClass);
            }
        };
    }
	// top menu
	$(".hlbMenuMain li").bind(makeMouseHandlers('hlbMenuMainSelected'));
	$(".mmMenuMain li").bind(makeMouseHandlers('mmMenuMainSelected'));

	function resizeLayer() {
        $('#layers').css({ 
            width: $document.width() + 'px',
            height: $document.height() + 'px'
        });
	}

	resizeLayer(); 
	$window.resize(resizeLayer);
});
    var http 				= createRequestObject();
//////////////////// Functions ///////////////////////////////////////////////////
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
 
function ShowSet(set_id,total)
{
	for (i=0; i<total; i++)
	{
		var div_id		= "ig_page" + i;
		document.getElementById(div_id).style.display	= "none";
	}
	var div_id		= "ig_page" + set_id;
	document.getElementById(div_id).style.display	= "block";
} 
/* function ShowSet(set_id,total)
{
	for (i=0; i<total; i++)
	{
		var div_id		= "ig_page" + i;
		document.getElementById(div_id).style.display	= "none";
	}
	var div_id		= "ig_page" + set_id;
	document.getElementById(div_id).style.display	= "block";
	
	http.open('get', '../../../../includes/set.php?p='+set_id);
  http.onreadystatechange = handlesetResponse;
  http.send(null);
}

function handlesetResponse()
{
	if(http.readyState == 4)
	{
		window.location.reload();
}
}  */
