﻿/// <reference path="jquery-1.3-vsdoc.js" />
/*
 *		USERINTERFACE.JS
 *
 *		Will setup any nessesary rollovers. Also sets up the text size selection.
 *		Requires jQuery.
 */
 
//Assigns rollover behavior to link icons
$().ready(function() {
	
	//home page links ?
	setRollover('#LinksBlock div a img');
	
	//action icons
	setRollover('#Actions div a img');	
	
	//the view marked record action has a funny rollover
	$('<img>').attr('src', $('#viewmarked img').attr('src').replace('.jpg', 'Highlight.jpg')); //preload the image
	$('#viewmarked').hover(
		function(){
			$(this).children('img').attr('src', $(this).children('img').attr('src').replace('.jpg', 'Highlight.jpg'));
			return false;
		} ,
		function(){
			$(this).children('img').attr('src', $(this).children('img').attr('src').replace('Highlight.jpg', '.jpg'));
			return false;
		}
	);

    //  Clear all the marked records
    $("a.clearMarked").click(function() {
        $("#cm").val('clear|');
        $("#mCount").val(0);
        $("#markedCount").html($("#mCount").val());

        //  If we're on a view page, reset the link
        $("#MarkRecord a").text("Mark this Record");

        //  If we're on a results page, clear all checks
        if($("input#pageCheck").size() > 0)
            $("input#pageCheck").get(0).checked = false;

        $("input.recordcheck").each(function(i) {
            this.checked = false;
            $(this).parent().parent().removeClass("marked");
        });

        if($('#markAllCallout').size() > 0) //hide any mark/clear callout
            $('#markAllCallout').slideUp("fast");

        //  Post this clear action to the callback
        $.post("/includes/session_callback.aspx", 'h=' + $("#searchHash").val() + '&cm=' + $("#cm").val());

        return false;
    });	
	
	//text size controls
	setRollover('#TextSizeControls img');
	
	//manage selected text size icon
	$('#TextSizeControls img').click(
		function(){ 
			if( !$(this).hasClass('selected') ) {
				//remove old selection and revert image
				$('#TextSizeControls img[class=selected]').attr('src', $('#TextSizeControls img[class=selected]').attr('src').replace('Highlight.jpg' ,'.jpg')).removeClass('selected');			
				$(this).addClass('selected');
				//set new font-size
				var textsizeLabel = $(this).attr('id').replace('text','').toLowerCase();
				$('#ContentCell').removeClass().addClass(textsizeLabel);
				//persist this information						
				document.cookie = 'textsize=' + textsizeLabel + '; path=/';
			}
	});	
});



//If given selectors exists, assign rollover behavior.  
//Make sure the rollover image is the original name with "Highlight" at the end.
function setRollover(selector)
{
	if( $(selector).size() > 0 ) {
		//preload the images
		$(selector).each(function() {
			$('<img>').attr('src', $(this).attr('src').replace('.', 'Highlight.'));
		});
	
		$(selector).hover(
			function(){ if( !$(this).hasClass('selected') ){
							$(this).attr('src', $(this).attr('src').replace('.', 'Highlight.'));
							return false;}
					  } ,
			function(){ if( !$(this).hasClass('selected') ){	
							$(this).attr('src', $(this).attr('src').replace('Highlight.' ,'.'));
							return false;}
					  }				
		);
	}
}


//assigns action to open and close callout
function setCalloutBehavior(triggerSelector, calloutSelector, toggle)
{
	//make sure the selectors are there
	if( $(triggerSelector).size() > 0 && $(calloutSelector).size() > 0 ) {
		//set trigger click event
		$(triggerSelector).click(function() {
			//toggle open/close callout
			if( $(calloutSelector).css("display") == "none" || $(calloutSelector).css("display") == "" ) {
				$(calloutSelector).css("display", "block");
			}
			else if( toggle ) {		
				$(calloutSelector).slideUp("fast");
			}	        
		});
		
		setCloseCallout(calloutSelector);
	}
	
	return false;  // prevent link default
}



//set "x" box click event on a callout
function setCloseCallout(calloutSelector)
{
	if( $(calloutSelector).children('.closeX').size() > 0 ) {
		$(calloutSelector).children('.closeX:first').click(function() {
			//close callout
			$(calloutSelector).slideUp("fast");
			
			return false;  //  prevent link default
		});
	}
}