$.noConflict();

var popup_min_width = 656;

function showGeneralAlert(text){
	GB_showCenter('Alert', '/popup/alert?message='+ escape(text), 153, popup_min_width);
}

function showVideoPlayer(element){
	if(typeof(element) == 'number'){
		var url = '/popup/media/'+ element;
	}else{
		var url = element.href;
	}
	GB_showCenter('Video Player', url, 540, 822);
}

function showImageViewer(element, width, height){
	width += 25;
	height += 56;
	if(width < popup_min_width){
		width = popup_min_width;
	}
	GB_showCenter('Image Viewer', element.href, height, width);
}

function showMissionPopup(element){
	if(typeof(element) == 'number'){
		var url = '/popup/mission/'+ element;
	}else{
		var url = element.href;
	}
	GB_showCenter('Mission', url, 410, popup_min_width);
}

function foundScavengerHuntItem(obj, mission_id, item_id, location_id){
	jQuery(obj).slideUp();
	GB_showCenter('Scavenger Hunt Item', '/popup/mission/'+ mission_id +'?item_id='+ item_id +'&location_id='+ location_id, 410, 656);
}

jQuery(document).ready(function(){

	/*
	if(typeof sIFR == "function"){
		sIFR.setup();
		sIFR.replaceElement(".story_submenu h3", named({sFlashSrc: BASE_URL +"assets/swf/sifr/trajanpro.swf", sColor: "#ffffff", sWmode: "transparent"}));
		sIFR.replaceElement("#about_the_war h3", named({sFlashSrc: BASE_URL +"assets/swf/sifr/trajanpro.swf", sColor: "#3e2910", sWmode: "transparent"}));
		sIFR.replaceElement("#about_the_war p", named({sFlashSrc: BASE_URL +"assets/swf/sifr/trajanpro.swf", sColor: "#270000", sWmode: "transparent"}));
		sIFR.replaceElement(".sifr", named({sFlashSrc: BASE_URL +"assets/swf/sifr/trajanpro.swf", sColor: "#000", sWmode: "transparent"}));
	};
	*/

	// close buttons or links for ALL popups
	jQuery(".popup_close").click(function(){
		//parent.parent.GB_hide();
	});

	// replace target="_blank"
	jQuery("[rel='external']").click(function(){
		this.target = "_blank";
	});		

	// fancy scroll to top on #top link!
	jQuery(".top").click(function(){
		jQuery("html").animate({scrollTop: 0}, "slow");
		return false;
	});

	jQuery('.media_popup').click(function(){
		var obj = jQuery(this);
		var rel = obj.attr('rel');

		if(rel){
			switch(rel){
				case 'video':
					showVideoPlayer(this);
					break;
				default:
					var width = parseInt(rel.replace(/.*[a-z]+\[([0-9]+),[0-9]+\].*/, '$1'));
					var height = parseInt(rel.replace(/.+\[[0-9]+,([0-9]+)\]/, '$1'));
					showImageViewer(this, width, height);
			}
		}else{
			alert('No image available');
		}

		return false;
	});

	jQuery('.mission_popup').click(function(){
		showMissionPopup(this);
		return false;
	});

	jQuery('.thumb').mouseover(function(){
		jQuery(this).children('.overlay').show();
	});

	jQuery('.thumb').mouseout(function(){
		jQuery(this).children('.overlay').hide();
	});

	jQuery('.encrypt_email').each(function(){
		if(this.nodeName == 'A'){
			this.attributes.href.value = decode_rot13(this.attributes.href.value);
		}

		this.innerHTML = decode_rot13(this.innerHTML);
	});
	
	jQuery('.drawer_top,.drawer_top *').click(function() {
		jQuery('#footer_legal').toggle("fast");
		return false;
	});

});

function decode_rot13(encrypted){
	var value = encrypted.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
	value = value.replace("++", '.');
	value = value.replace("+", '@');

	return value;
}

// TOGGLE FOOTER LEGAL INFORMATION
function legal_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}
