/*				_javascript/default.js
*/

var requiredFieldsARR=new Array();

// pageload
$(document).ready(function() {    

	$('#myForm').submit(function(){

		//alert($('#field_myModule').val());
		//alert($('#field_myFunction').val());
		
		return false;

	});

	// dynamic validation

	if(typeof(requiredFieldsARR)!='undefined'){
		for(i=0;i<requiredFieldsARR.length;i++){

			$('#'+requiredFieldsARR[i]).blur(function(){

					if($(this).val()==""){

						$(this).addClass('blockError');
						$('label[for="'+this.id+'"]').children().addClass('error');


					} else {

						$(this).removeClass('blockError');
						$('label[for="'+this.id+'"]').children().removeClass('error');

					}


			});



		}
	}

	openModal=function(id,width,height,sourceElement){

		$('.flashObject').css('visibility','hidden');

		var id='#modal_'+id;

		var documentMargin = ($(window).width()-$('body').width())/2;
		var maskHeight = $(document).height();
		var maskWidth = $(window).width()+documentMargin;
		var maskX = 0-documentMargin;

		// Set height and width to mask to fill up the whole screen  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
		$('#mask').css({'left':maskX});  

		// transition effect       
		$('#mask').fadeTo(1000,0.85);      
		$('#mask').fadeTo(500,0.65);
/*
		if(sourceElement!=null){

			// resize and position to sourceElement
			var sourceWidth=sourceElement.width();
			var sourceHeight=sourceElement.height();
			var sourceLeft=sourceElement.offset().left;
			var sourceTop=sourceElement.offset().top-$(window).scrollTop();;

			$(id).width(sourceWidth);
			$(id+'>iframe').width(sourceWidth);
			$(id).height(sourceHeight);
			$(id+'>iframe').height(sourceHeight);
			$(id).css('left',sourceLeft+'px');
			$(id).css('top',sourceTop+'px');

			// animate to full size and center
			var left=($(window).width()/2)-(width/2);
			var top=($(window).height()/2)-(height/2);
	
			$(id).fadeIn(500).animate({width:width,left:left,height:height,top:top},400);


		} else {
*/
			if(width!=null){
				$(id).width(width);
				$(id+'>iframe').width(width);
			}

			if(height!=null){
				$(id).height(height);
				$(id+'>iframe').height(height);
			}


			var winH = $(window).height();  
			var winW = $(window).width();

			var scrollTop = $(window).scrollTop();


			$(id).css('top',  (winH/2-$(id).height()/2));
			$(id).css('left', (winW/2)-($(id).width()/2)); 

			$(id).fadeIn(500);


//		}


	}

 


	closeModalWindow=function(id,timeout,callback){
		

		setTimeout(function(){
			$('#mask').fadeOut(1000);
			$('#modal_'+id).fadeOut(1000);
			if(callback){
				setTimeout(function(){
					eval(callback);
				},1000);
			}
		},timeout);
	 };

	// used for child iframes
	closeAllModalWindows=function(){

		$('.modalWindow').hide();  
		$('#mask, .modalWindow').hide();  

	}



	// if close button is clicked  
	$('.modalExit').click(function (e) {  
		//Cancel the link behavior  
		e.preventDefault(); 
		$('#mask, .modalWindow').hide(); 
		parent.closeAllModalWindows();
	});       
       
	// if mask is clicked  
	$('#mask').click(function () {  

		$('.flashObject').css('visibility','visible');

		$(this).hide();
		$('.modalWindow').hide();
		$('.contextMenu').hide(500);

	});  


	loadIframe=function(id,src){

		var iframe=document.getElementById('iframe_'+id);
		if(src){
			iframe.src=src;
		} else {
			iframe.src=iframe.src;
		}
	}

	loadModal=function(src,modalID){

		if(modalID==null){modalID='myModal';}
		
		var iframe=document.getElementById('iframe_'+modalID);
		iframe.src=src;
		
	}

	resizeModal=function(width,height,modalID){

		if(modalID==null){modalID='myModal';}
		$('#modal_'+modalID).width(width);
		$('#modal_'+modalID).height(height);
		$('#iframe_'+modalID).width(width);
		$('#iframe_'+modalID).height(height);

	}

       
}); 




/* form functions */

function switchFunction(myFunc,myModule){
// switches function select 
// submits form





		var myFunctionInput=document.getElementById('field_myFunction');
		var myModuleInput=document.getElementById('field_myModule');
		myFunctionInput.value=myFunc;
		myModuleInput.value=myModule;

		document.myForm.submit();

}



function changeFormAction(url){

		document.myForm.action=url;

}


/* helper functions */


function navigateURL(url){
// used for buttons

	window.location.href=url;

}



function formatOrdinalSuffix(n) {

	n=String(n);
	n_lastTwo=n%100;

	if((n_lastTwo >10&&n_lastTwo<14)||n==0){
	
		formatted=n+"th";

	} else {

		switch(n.substr(n.length-1,1)) {
			case '1':
				formatted=n+"st";
				break;
			case '2':    
				formatted=n+"nd";
				break;
			case '3':
				formatted=n+"rd";
				break;
			default:
				formatted=n+"th";
				break;
		 }
	 }

	 return formatted;
}



// navigation 

$(document).ready(function(){

	$('#navigation2 > ul > li').hover(
		
		function(){
			$(this).children('.submenu').slideDown();
		},
		function(){
			$(this).children('.submenu').slideUp();
		}

	);



});




function loadTipListeners(){

	$('.tippable').hover( // handles tool tips
		function(){

			var tip=$('#tip_'+$(this).attr('id'));
			
			if(tip.parent().hasClass('tipContainer')==false){
				var tipContainer=$(document.createElement('div'));
				tipContainer.addClass('tipContainer');
				tip.parent().append(tipContainer);
				tipContainer.append(tip);
				tip.show();
				var tipBottomContainer=$(document.createElement('div'));
				tipBottomContainer.addClass('tipBottom');
				var tipBottom=$(document.createElement('img'));
				tipBottomContainer.addClass('tipBottomImg');
				tipBottom.attr('src',_masterURL+'_images/_structure/icon_tipBottom.png');
				tipBottomContainer.append(tipBottom);
				tipContainer.parent().append(tipBottomContainer);
				tipBottom.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='http://localhost/sassfa/_images/_structure/icon_tipBottom.png')");
			} else {
				var tipContainer=tip.parent();
				var tipBottomContainer=tipContainer.parent().children('.tipBottom');
				if(tipContainer.is(':animated')){tipContainer.clearQueue();}
			}

			tipContainer.fadeTo(200,1);
			tipBottomContainer.fadeTo(200,1);
			tipContainer.css('width',tip.width());
			tipContainer.css('height',tip.height());
			var tippableLeft=$(this).offset().left-tip.width();
			var tippableTop=$(this).offset().top-tip.height();
			if(tippableLeft<-10){
				var reverse=true;
				tippableLeft=$(this).offset().left+tipContainer.parent().width();
			}
			tipContainer.css('left',tippableLeft);
			if(reverse==true){
				tipBottom.attr('src',_masterURL+'_images/_structure/icon_tipBottom-reverse.png');
				tipBottom.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='http://localhost/sassfa/_images/_structure/icon_tipBottom-reverse.png')");
				tipBottomContainer.css('left',tipContainer.offset().left-10);
			} else {
				tipBottomContainer.css('left',tipContainer.offset().left+tipContainer.width()-240);
			}
			if(tippableTop<10){tippableTop=10;}
			tipContainer.css('top',tippableTop);
			tipBottomContainer.css('top',tippableTop+tipContainer.height()+1);
			
		},
		function(){
			var tip=$('#tip_'+$(this).attr('id'));
			var tipContainer=tip.parent();
			var tipBottomContainer=tipContainer.parent().children('.tipBottom');
			var tipBottom=tipBottomContainer.children('.tipBottomImg');
			//tipBottom.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='http://localhost/sassfa/_images/_structure/icon_tipBottom.png')");
			tipContainer.fadeOut();
			tipBottomContainer.fadeOut();
		}
	);
}


$(document).ready(function(){ // need to generate modal_myTip for each tip that doesn't already have one

	
var i;
for (i in document.images) {
    if (document.images[i].src) {
        var imgSrc = document.images[i].src;
        if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
            document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
        }
    }
}

	loadTipListeners();


});





/*			created on [ 09.29.2009 ] Grenard Madrigal
/*			updated on [ 09.29.2009 ] Grenard Madrigal
/*			evolve, create © 2009
*/












