// JavaScript Document
function getElementLeft(Elem) {
	var ns4 = (document.layers)? true:false, elem;
	if (ns4) {
		 elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		if(document.getElementById) {
			 elem = document.getElementById(Elem);
		} else if (document.all){
			 elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}

function clearInputValue(obj,value){
	if($(obj).value == value){
		if($(obj).type == "texarea"){
			$(obj).innerHTML = "";
		}else{
			$(obj).value = "";
		}
	}
}
function setInputValue(obj,value){
	if($(obj).value == ""){
		if($(obj).type == "texarea"){
			$(obj).innerHTML = value;
		}else{
			$(obj).value = value;
		}
	}
}
function getIframeContents(el){
	 return  $(el).contentWindow.document.body.innerHTML;
}
function stripHTML(oldString) {
	return oldString.replace(/(<([^>]+)>)/ig,""); 
}
function checkCharMin(obj,minChar){
	var text = getIframeText(obj);
	if(text.length >= minChar){
		return true;	
	}else{
		return false;	
	}
}

/*window.addEvent("domready", function(){*/
//var alertbox,publishalertbox,savinganimation,spellcheck																			 
//	if($('alertbox'))	alertbox = $('alertbox');
//	if($('publishalertbox'))	publishalertbox = $('publishalertbox');
//	if($('savinganimation'))	savinganimation = $('savinganimation');
//	if($('spellcheck'))	spellcheck = $('spellcheck');
/*})*/
function mbAlert(msg,rel,height){
	/*$('alertboxmsg').innerHTML = msg*/
	$('alertbox').setProperty('href','../multi_popups/alertbox.php?msg='+msg);
	$('alertbox').setProperty('rel',rel);
	/*alertmb.options.initialHeight = height;*/
	alertmb.open($('alertbox'));
}
function isBlank(obj){
	if($(obj)){
		if($(obj).value=='') return true;
		else return false;
	}else return true;
}
function openSpellCheck(obj,maxChar){
	var contents = $(obj).contentWindow.document.body.innerHTML;
	contents = contents.replace('&nbsp;',' ');
	$('spellcheck').setProperty('href',('../googiespell/index.php?obj='+obj+'&maxchar='+maxChar+'&contents='+encodeURI(contents)));
	alertmb.open($('spellcheck'));
}
function updateEditorFromSpellCheck(obj,contents){
	$(obj).contentWindow.document.body.innerHTML =  contents;
	alertmb.close();
}
function savingAnimation(){
	$('OverlayContainer').style.display = '';
	setTimeout('savingmb.open($(\'savinganimation\'))',1000);
	setTimeout("$('frminput').submit()",6000)
}
function alertBeforeSave(save){
	if (typeof save == 'undefined' ) save = 'parent.saveItem()';
	mbAlert('By selecting to save your submission you can complete your work any time for the next 7-days by accessing the article via your FragTag "My Contributions" window. To send your article to our editors for publication you will need to select "Publish".<div style="padding-top:15px; text-align:center"><input type="image" name="savebutton" id="savebutton"  src="../images/btn_save.gif" value="save" onclick="'+save+'"/></div>','width:400,height:150',150);
	return false;
}
function saveItem(upload,add){
	if (typeof upload == 'undefined' ) upload = false;
	if (typeof add == 'undefined' ) add = false;
	doBeforeSubmit();
	$('buttonAction').value = "SAVE";
	doSave(upload,add);
}
function saveItem2(){
	doBeforeSubmit();
	$('buttonAction').value = "SAVE";
	savingAnimation();
}
function alertBeforePublish(publish){
	if (typeof publish == 'undefined' ) publish = '';
	$('publishalertbox').setProperty('href','../multi_popups/publish_alertbox.php?params='+publish);
	alertmb.open($('publishalertbox'));
	return false;
}
function publishItem(upload,add){
	if (typeof upload == 'undefined' ) upload = false;
	if (typeof add == 'undefined' ) add = false;
	doBeforeSubmit();
	$('buttonAction').value = "PUBLISH";
	doSave(upload,add);
}

function getEditorText(obj){
	var text = escape(getIframeContents(obj));
	text = text.replace('%A0','');
	text = unescape(text);
	return text
}	
function doSave(upload,add){
	if(alertmb.opened){
		if(add){
			new Ajax('pre_add.php',{
				method: 'get',
				data: { 'time' : Math.round(new Date().getTime()/1000) },
				onComplete: function(response) { 
											var reviewid = response;
													$('reviewID').value = reviewid;
													$('frame').contentWindow.document.getElementById('reviewID').value = reviewid;
													alertmb.options.onClose = function(){
																										document.getElementById('frame').contentWindow.doBeforeSubmit();
																										document.getElementById('frame').contentWindow.sidebarSavingAnimation();
																										/*document.getElementById('frame').contentWindow.document.frminput.submit()	*/			
																										/*savingAnimation()*/
																										};
													alertmb.close();
										}
			}).request();
		}else{
			if(upload){
				document.getElementById('frame').contentWindow.doBeforeSubmit();
				document.getElementById('frame').contentWindow.sidebarSavingAnimation();
				alertmb.close();
			}else{
				alertmb.options.onClose = function(){savingAnimation();}
				alertmb.close();
			}
		}
	}else{
		if(upload){
			document.getElementById('frame').contentWindow.doBeforeSubmit();
			document.getElementById('frame').contentWindow.sidebarSavingAnimation();
			/*document.getElementById('frame').contentWindow.document.frminput.submit()*/	
		}else{
			savingAnimation();
		}
	}
}

	function checkFileInput(el){
		if(!document.getElementById(el).value) {
			return false;
		}else{
			return true;
		}
	}
function disableButton(el,src){
	if($(el)){
		if (typeof src == 'undefined' ) src = '';
		if(!$(el).disabled){
			$(el).disabled = true;
			if(src !=''){
				$(el).src = src;
			}
		}
	}
}
function enableButton(el,src){
	if($(el)){
		if (typeof src == 'undefined' ) src = '';
		if($(el).disabled){
			$(el).disabled = false;
			if(src !=''){
				$(el).src = src;
			}
		}
	}
}
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}
function checkTextMin(obj,minChar){
	var text = $(obj).value;
	if(text.length >= minChar){
		return true;	
	}else{
		return false;	
	}
}
function searchMultibox(keyword){
	if(keyword!='Search'){
		$('generalbox').setProperty('rel','height:400,width:800');
		$('generalbox').setProperty('href','../multi_popups/search.php?k='+keyword);
		generalmb.open($('generalbox'))
	}
}
function openUserArticlesMultibox(id){
		$('generalbox').setProperty('rel','height:400,width:800');
		$('generalbox').setProperty('href','../multi_popups/user_articles.php?userID='+id);
		generalmb.open($('generalbox'));
}

function openPodcastWindow(urlID){
	var ts = window.open(urlID+"&noframe=1", "podcastwin", "status=1,width=370,height=120");
  box4.close();
}

function showHide(id){
		if($(id).getStyle('display')=='none'){
				$(id).setStyle('display','');
		}else{
				$(id).setStyle('display','none');
		}
}

function setRating(obj,rating){
		$(obj).value = rating;
}

function checkStorylineDisableRating(){
	return $('storylineDisableRating_0').checked;
}
function checkStoryline(){
	if(!checkStorylineDisableRating()){
		return checkCharMin('storylinetextbox',500);
	}else return true;
}
function checkRating(obj){
	if($(obj).value!='0.0' && $(obj).value!='0' && !isBlank('title')) return true;
	else return false;
}
function checkStorylineRating(){
	if(!checkStorylineDisableRating()){
		return checkRating('section2Rating');
	}else return true;
}

function openContributeMultibox(type,userID){
	var swf;
	if(type=='review'){
		$('generalbox').setProperty('rel','height:341,width:537');
		swf = 'review_popup';
	}else	if(type=='editorial'){
		window.top.location = 'http://www.fragtools.com/sub_pages/editor-input.php?action=add';
		return;
	}else if(type=='fragment'){
		$('generalbox').setProperty('rel','height:520,width:537');
		swf = 'fragment_popup';
	}else if(type=='userfrags'){
		$('generalbox').setProperty('rel','height:393,width:537');
		swf = 'viewUserFrags_popup';
	}else if(type=='news'){
		$('generalbox').setProperty('rel','height:520,width:537');
		swf = 'submit_news_popup';
	}else if(type=='workspace'){
		window.top.location = 'http://www.fragtools.com/manager/';
		return;
	}else return;
		$('generalbox').setProperty('href','http://www.fragtools.com/multi_popups/contribute.php?swf='+swf+'&userID='+userID);
		generalmb.open($('generalbox'));
}

function openDLCParentMultibox(id){
		$('generalbox').setProperty('rel','height:440,width:741');
		$('generalbox').setProperty('href','http://www.fragtools.com/multi_popups/dlc.php?reviewID='+id);
		generalmb.open($('generalbox'));
}

function openUserFragmentsMB(id,frag){
	openGeneralMB({'href':'http://www.fragtools.com/multi_popups/user_fragments.php?userID='+id+'&fragID='+frag,'rel':'height:400,width:520'});
}
function openGeneralMB(property){
		$each(property,function(value, key){
			$('generalbox').setProperty(key,value);
		})
		generalmb.open($('generalbox'));
}

function alertMB(msg,width,height){
	if (typeof width == 'undefined' ) width = '400';
	if (typeof height == 'undefined' ) height = '80';
	openGeneralMB({'href':'http://www.fragtools.com/multi_popups/alertbox.php?msg='+msg,'rel':'height:'+height+',width:'+width});
}
function openReportBugMB(){
	openGeneralMB({'href':'http://www.fragtools.com/multi_popups/report_bug_start.php','rel':'height:400,width:400'});
}
function openReportPlagiarismMB(id,type){
	openGeneralMB({'href':'http://www.fragtools.com/multi_popups/report_plagiarism_start.php?articleID='+id+'&type='+type,'rel':'height:100,width:400'});
}

function resetTabs(){
	moviest.changeTo(1);
	gamesst.changeTo(1);
	techst.changeTo(1);
}
function searchReleaseDate(keywordEl,typeEl){
	keyword = $(keywordEl).value;
	if($(typeEl+'_1').checked){
		type = 'publisher';
	}else{type = 'title';}
	$('searchbox').setProperty('rel','height:400,width:559');
	$('searchbox').setProperty('href','http://www.fragtools.com/multi_popups/search_release_date.php?k='+keyword+'&type='+type);
	searchmb.open($('searchbox'));
}
function createSearchReleaseDatesMultibox(el,id){
	/*searchmb.close()*/
	(function(){rDateSearchmb = new MultiBox(el, {useOverlay: false, descClassName: el+'Desc'})
	rDateSearchmb.open($(id))}).delay(2000);
}
function openGamingNewsMultibox(index,obj){
	gnmbox[index].open($(obj));
}
function openNewsMultibox(obj){
	gamingnewsmb.open($(obj));
}
function createMultibox(){
	window.addEvent("domready", function(){
		gamingnewsmb = new MultiBox('gamingnewsmb', {useOverlay: false});
	});
}
function openRDatesSubscribe(id){
	openGeneralMB({'href':'multi_popups/release_date_subscribe.php?id='+id,'rel':'height:120,width:400'});
}

function openMainPointSources(num){
	openGeneralMB({'href':'../multi_popups/main_point_sources.php?num='+num,'rel':'height:430,width:400'});
}

function getFileContents(container,url){
	
			new Ajax('includes/ajax_php/get_file_contents.php',{
				method: 'get',
				data: { 'time' : Math.round(new Date().getTime()/1000),'url':url },
				onComplete: function(response) { 
													$(container).setHTML(response)
													if(container=='gotapexContainer') mooScroller.update()
										}
			}).request();
}

/*Jquery*/
var navHoversDisabled = false;

j.fn.orbMenu = function() {
	var shadowDefault = .55;
	var shadowHover = .20;

	this.each(function() {
			var self = this;
			var itemName = this.id.substring(2);
			j('.label', this).remove().appendTo(this).css('opacity', 0);
			j('.label', this).css('background','url(/images/label-'+itemName+'.png) no-repeat')
			j('a', this).html('<span class="imgs"><img class="grey" src="/images/orb-' + itemName + '.png" /></span>');		
			j(this).append('<span class="shadow"></span>');
			if(!j.browser.msie){
				j('.grey', this).css('opacity', 1)
				j('.shadow', this).css('opacity', shadowDefault)
			}
	});	

	var easingImage = 'easeOutBack';
	var easingShadow = 'easeOutExpo';
	var easingLabel = 'easeOutSine';
	
	var hovers = [function() {
		if (navHoversDisabled) return;
		// Image
		j('a', this).stop().animate({'height': '110px'}, 900, easingImage);
		
		// Shadow
		shadowCss = j.browser.msie ? {'bottom': '-15px'} : {'bottom': '-15px','opacity': shadowHover}  ;
		j('.shadow', this).stop().animate(shadowCss, 900, easingShadow);
		
		// Label
		j('.label', this).stop().animate({'bottom': '30px','opacity': 1}, 600, easingLabel);

	}, function() {

		// Image
		j('a', this).stop().animate({'height': '71px'}, 900, easingImage);

		// Shadow
		shadowCss = j.browser.msie ? {'bottom': '-7px'} : {'bottom': '-7px','opacity': shadowDefault}  ;
		j('.shadow', this).stop().animate(shadowCss, 900, easingShadow);

		// Label
		j('.label', this).stop().animate({'bottom': '10px','opacity': 0}, 700, easingShadow);
	}];

	j(this).hover.apply(this, hovers);
};


j.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}
	
j.fn.airlock = function(xml){
	this.html('<div class="door"></div><div class="leftDoor"></div><div class="rightDoor"></div><a class="imagelink" href="#"><div><p></p></div></a>')
	var buttons = '<div class="buttons"><div id="n-home" class="orb top"><a class="link" href="/index.php"><span class="label">Home</span></a></div><div id="n-fragtag" class="orb top"><a class="link" href="/fragtag/landing.php"><span class="label">Home</span></a></div></div>';
	var padNav  = j('<div class="padnav"><div class="dpad"><p class="prev">&nbsp;</p><p class="next">&nbsp;</p></div>'+buttons+'</div>')
	this.after(padNav)
	j('.orb',padNav).orbMenu();
	var $this = this
	j.ajax({type: "GET",url: xml, dataType: "xml",
		success: function(xml) {
			var items = '';
			j(xml).find('img').each(function(){
				var href = j(this).attr('link');
				//items += '<a href="'+(href!=''? href : '#" onclick="return false;"' )+'">';
				items += '<img src="'+j(this).text()+'" link="'+(href!=''? href : '#' )+'" />';
				//items += '</a>';
			});
			j('.door',$this).before(items)
			
			j($this).cycle({
				slideExpr: 'img',
				speed:1,
				timeout:4000,
				prev:'.padnav .prev',
				next:'.padnav .next',
				delayShow: 500,
				before:slideDoor
			});
		}
	});
	
	function slideDoor(){
		//alert(j(this).attr('link'))
		j('.imagelink',$this).css('display','none')
		j('.imagelink',$this).attr('href',j(this).attr('link'))
		
		j('.leftDoor',$this).css('display','block')
		j('.leftDoor',$this).animate({ backgroundPosition : '0'},{queue:true,duration:500});
		j('.leftDoor',$this).animate({ backgroundPosition : '0'},{queue:true,duration:500});
		j('.leftDoor',$this).animate({ backgroundPosition : '-300px'},{queue:true,duration:500,complete:function(){ j('.leftDoor',$this).css('display','none'); j('#link').css('display','block'); }});
	
		j('.rightDoor',$this).css('display','block')
		j('.rightDoor',$this).animate({ backgroundPosition : '0'},{queue:true,duration:500});
		j('.rightDoor',$this).animate({ backgroundPosition : '0'},{queue:true,duration:500});
		j('.rightDoor',$this).animate({ backgroundPosition : '300px'},{queue:true,duration:500,complete:function(){ j('.rightDoor',$this).css('display','none')}});
	}
}