//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	URL popup functionality
//-------------------------------------------------------------------------------------------------------
    var _popupTracker = {}
    var _popupCounter = 0;

	var	SHpopup	= null;

    $.fn.openPopupWindow = function(options)
    {
		var SHpopup;

        var defaults = {
            height: 580, // sets the height in pixels of the window.
            width: 820, // sets the width in pixels of the window.
            toolbar: 0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
            scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
            status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
            resizable: 1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
            left: 0, // left position when the window appears.
            top: 0, // top position when the window appears.
            center: 1, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
            createnew: 0, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
            location: 0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
            menubar: 0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
        };

        var options = $.extend(defaults, options);

        var obj = this;

        // center the window
        if (options.center == 1)
        {
            options.top = (screen.height - (options.height + 110)) / 2;
            options.left = (screen.width - options.width) / 2;
        }

        var parameters = "location=" + options.location +
                         ",menubar=" + options.menubar +
                         ",height=" + options.height +
                         ",width=" + options.width +
                         ",toolbar=" + options.toolbar +
                         ",scrollbars=" + options.scrollbars +
                         ",status=" + options.status +
                         ",resizable=" + options.resizable +
                         ",left=" + options.left +
                         ",screenX=" + options.left +
                         ",top=" + options.top +
                         ",screenY=" + options.top;

        // target url
        var target = obj.attr("href");       

		var windowname	= "sacredheart";

        // test if popup window is already open, if it is, just give it fokus.        
 //       var popup = _popupTracker[windowname];
//        if (options.createnew == 0 && popup !== undefined && !popup.closed)
        if(!SHpopup || SHpopup.closed)
        {
			// open window
			SHpopup = window.open(target, windowname, parameters);
//			_popupTracker[windowname] = popup;
//			_popupTracker[windowname].focus();
  			SHpopup.focus();
        } 
        else
        {
//            var name = "PopupWindow" + _popupCounter;
//            _popupCounter++;

//            _popupTracker[windowname].focus();
//			_popupTracker[windowname].location=target;
  //          _popupTracker[windowname].focus();
//            _popupTracker[windowname].focus();
			SHpopup.location=target;
            SHpopup.focus();
        }

//        return false;
    };        


//-------------------------------------------------------------------------------------------------------
//	JAuery hide empty menus
//-------------------------------------------------------------------------------------------------------
$(function(){

	$(document.body).ready
	(
		function(){$(this).find('ul.m2').HideEmpty();}
	);
});

jQuery.fn.HideEmpty = function() {
  return this.each(function(){
	var itemcount	= $(this).find('li').length;
	if( !itemcount || itemcount == 0 )
	  {
		$(this).css( "visibility", "hidden" );
	  }
  });
};

$(document).ready(function() 
{
	//	Fix flash object z-index
	$("object").attr("wmode","transparent");

	$("table.sortable").tablesorter(); 

	//	Galery lightbox - load video
	$("a.loadmovie").click(function () {

//		$("#vt").load( $(this).attr("href") );
		$("#vt").attr( "src", $(this).attr("href") );

	//				$("#"+slideshow_id).get( "http://www.spaceweather.com/" );

		return false
    });    


	//	Position the menu
//	$("#b-servicesampinstitutes").ready(function() 

	if( document.getElementById( "b-servicesampinstitutes") )
	{
		var p			= $("#b-servicesampinstitutes");

		if( p )
		{
			var menupos		= p.position();

			menutop			= menupos.top + $("#b-servicesampinstitutes").height();
			menuleft		= menupos.left - 100;

			$("#servicesmenu").css("top", menutop );
			$("#servicesmenu").css("left", menuleft );

			//	Services Menu Custom Display
			$("#b-servicesampinstitutes").hover(
				function () {
					$("#servicesmenu").show();
				}, 
				function () {
					$("#servicesmenu").hide();
				}
			);

			$("#servicesmenu").hover(
				function () {
//					button_idx	= $(this).attr("id").substr(2,$(this).attr("id").length);
					$("#img-servicesampinstitutes").attr("src",menuimages_hover["servicesampinstitutes"] );
					$("#servicesmenu").show();
				}, 
				function () {
					$("#img-servicesampinstitutes").attr("src",menuimages_default["servicesampinstitutes"] );
					$("#servicesmenu").hide();
				}
			);
		}
	}
//	});    







	//	Galery lightbox - load video
	$("a").click(function (event)
	{
		urls	= new Array();
		urls.push( 'www.health-news-and-information.com' );
//		urls.push( 'www.cnn.com' );
//		urls.push( 'www.bluesnews.com' );

		link	= $(this).attr("href");
		domain	= jQuery.url.setUrl( link ).attr("host");

		array_pos	= jQuery.inArray( domain, urls );

		if( array_pos != -1 )
		{
			event.preventDefault();
			$(this).openPopupWindow();
		}
    });    




} 
); 



//-------------------------------------------------------------------------------------------------------
//	Super Simple Tabs 1.0
//		http://andreaslagerkvist.com/jquery/super-simple-tabs/
//-------------------------------------------------------------------------------------------------------
jQuery.fn.superSimpleTabs = function () {
    return this.each(function () {
        var ul = jQuery(this);

        // Go through all the in-page links in the ul
        ul.find('a[href^=#]').each(function (i) {
            var link = jQuery(this);

            // Hide all containers cept the first
            if (i) {
                jQuery(link.attr('href')).hide();
            }
            else {
                link.addClass('selected');
            }

            // When clicking link
            link.click(function () {
                // Hide selected link's containers
                jQuery(ul.find('a.selected').removeClass('selected').attr('href')).hide();

                // Show this one's
                jQuery(link.addClass('selected').attr('href')).show();

                return false;
            });
        });
    });
};

