$(document).ready( function() {

	// Apply sIFR
	if(typeof sIFR == "function"){

	// This is the preferred "named argument" syntax
		sIFR.replaceElement(named({sSelector:"#swfHeadings h3", sFlashSrc: "/includes/DesertDogHmkBold.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#000000", sWmode:"transparent"}));

		sIFR.replaceElement(named({sSelector:"#swfHeadings h4", sFlashSrc: "/includes/DesertDogHmkNormal.swf", sColor:"#740303", sLinkColor:"#740303", sBgColor:"#ffffff", sHoverColor:"#ffffff", sWmode:"transparent"}));
	};

    
    $("a[href^='http']").each(function(i) {
        var $this = $(this);

        $this.bind("click", function() {
           pageTracker._trackPageview("/outgoing/"+$this.attr('href'));
        });       
    });

	$("a[href$='pdf'],[href$='doc'],[href$='xls'],[href$='jpg'],[href$='gif'],[href$='ppt']").each(function(i) {
        var $this = $(this);
        $this.bind("click", function() {
           pageTracker._trackPageview("/downloads/"+$this.attr('href'));
        });       
    });
});


function imageAdjust() {
	// find all containers with the imageAdjust class and center images horizonally and vertically
	$(".imageAdjust").each(function(i) {
		var heightDiff = $(this).find("img").height() - $(this).height();
		var widthDiff = $(this).find("img").width() - $(this).width();
		
		if(heightDiff > 0) {
			$(this).find("img").css("marginTop",-heightDiff/2);
		}

		if(widthDiff > 0) {
			$(this).find("img").css("marginLeft",-widthDiff/2);
		}
    });
}



/*
 * Popup window script 
 *  
 * Example markup 
 * <a href="mypage.html" onclick="popUpWin(this.href,'console',660,520);return false;" title="Open popup window">Link text</a>
 */

var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}


function ShowSection(parentElement, selectedElement)
{
	alert(parentElement + " " + selectedElement.value);
	
	// hide all child div's inside section_area div 
	$("#" + parentElement +" > div").hide();	
	// show the element	
	$("#" + selectedElement.value).show();
	
}






/****************** EMAIL DECRYPTION *********************/
function decrypt_string(crypted_string) {

	var numbers = crypted_string.split(' ');			
	n = numbers[0];	decryption_key = numbers[1];			
	numbers[0] = ""; numbers[1] = "";				
	crypted_string = numbers.join(" ").substr(2);


	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');
	var i;
	
	for(i = 0; i< crypted_characters.length; i++) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	


	return decrypted_string;
}


// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}


function sendEmail(dat)
{
    document.location.href='mailto:' + do_decrypt ( dat );
}


function do_decrypt(dat)
{ 
	return decrypt_string ( dat, 0, 0 ,'');
}

