﻿$(document).ready(function(){
	$('#fontsizer').jfontsizer({
		applyTo: '#content',
		changesmall: '2',
		changelarge: '2',
		expire: 30
	});
	
	$('#go').click(function(){
	    var emailVal = $('#textfield').val();
	    //alert(emailVal);
	    if($.trim(emailVal) != "" /*&& $.trim(emailVal) != "Enter email"*/) {
	        window.open('http://oi.vresp.com?fid=157fea4066&email_address=' + emailVal, 'vr_optin_popup', 'scrollbars=yes,width=600,height=450');
	        return true;
	    }
	});
	
	theRotator();
	
	if ($("textarea.htmleditor").length > 0){
	     $('textarea.htmleditor').tinymce({
            // General options
            theme: "advanced",
            plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
            // Theme options
            theme_advanced_buttons1: "bold,italic",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            //theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing: false,
            // Example content CSS (should be your site CSS)
            content_css: "css/content.css",
            // Drop lists for link/image/media/template dialogs
            template_external_list_url: "lists/template_list.js",
            external_link_list_url: "lists/link_list.js",
            external_image_list_url: "lists/image_list.js",
            media_external_list_url: "lists/media_list.js",
            // Replace values for the template plugin
            template_replace_values: {
                username: "Lions Gate Hospital",
                staffid: "991234"
            }
        });
    }
});

/*$(document).ready(function() { 
	$("#landing-spot").tooltip({
		effect: 'toggle',
		tip: '#bubble',
		offset: [150,220],
		relative: true
	}); 
});
*/

function dosearch(type,controlID) {
	if(type == 1) {
	    var keyword = document.getElementById(controlID).value;
	    if(trim(keyword).length == 0 || trim(keyword) == "Type name here") {
	        alert("Please enter a name.");
	        return false
	    }
		window.location.href = "/tribute/search-results.aspx?name=" + keyword;
	}
	
	if(type == 2) {
	    var cat = document.getElementById(controlID).value;
	    if(cat == "0") {
	        alert("Please choose a category.");
	        return false
	    }
		window.location.href = "/tribute/search-results.aspx?cat=" + cat;
    }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#banner-image-ie ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#banner-image-ie ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#banner-image-ie ul li.show')?  $('div#banner-image-ie ul li.show') : $('div#banner-image-ie ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#banner-image-ie ul li:first') :current.next()) : $('div#banner-image-ie ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

/************************************************************\
**************************   Popup   *************************
\************************************************************/

//0 means disabled; 1 means enabled;
var popupStatus = 0;

//disabling popup 
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $(".backgroundPopup").fadeOut("slow");
        $(".popupBody").fadeOut("slow");
        $("#password-form .login-input").val('');  //clear text
        $("#Login1_lbl_pass").text('');
        popupStatus = 0;
    }
}

//loading popup
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 1)
        disablePopup();
   
    if (popupStatus == 0) {
        $(".backgroundPopup").css({
            "opacity": "0" //0.7
        });
        $(".backgroundPopup").fadeIn("slow");
        $(".popupBody").fadeIn("slow");
        //alert("here " + pid + " - " + popupStatus);
        popupStatus = 1;
    }
}

//positioning popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(".popupBody").height();
    var popupWidth = $(".popupBody").width();
    //centering
    $(".popupBody").css({
        "position": "absolute",
        //		"top": windowHeight/2-popupHeight/2,
        //		"left": windowWidth/2-popupWidth/2
        "top": 35,
        "left": -22
    });
    //only need force for IE6
    $(".backgroundPopup").css({
        "height": windowHeight
    });
}

//CONTROLLING EVENTS
$(document).ready(function() {

    //Click out event!
    $(".backgroundPopup").click(function() {
        disablePopup();
    });

    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

    $("#forgot-pass").click(function() {
        centerPopup();
        loadPopup();
    });

    //CLOSING POPUP
    $(".popupClose").click(function() {
        disablePopup();
        return false;
    });
});

$('#mainnav .nav').superfish({
	delay: 500,                         
	animation: { opacity: 'show' },  
	speed: 'fast',                         
	autoArrows: false,
	dropShadows: false
});		