// JavaScript Document
// JavaScript Document
function getCookies(name){
	 //in cookie when name is the empty string.
	 if(name == '')
		return('');
	 
	 name_index = document.cookie.indexOf(name + '=');
	 
	 if(name_index == -1)
		return('');
	 
	 cookie_value =  document.cookie.substr(name_index + name.length + 1, 
											document.cookie.length);
	 
	 //All cookie name-value pairs end with a semi-colon, except the last one.
	 end_of_cookie = cookie_value.indexOf(';');
	 if(end_of_cookie != -1)
		cookie_value = cookie_value.substr(0, end_of_cookie);

	 //Restores all the blank spaces.
	 space = cookie_value.indexOf('+');
	 while(space != -1)
		  { 
		  cookie_value = cookie_value.substr(0, space) + ' ' + 
		  cookie_value.substr(space + 1, cookie_value.length);
						 
		  space = cookie_value.indexOf('+');
		  }

	 return(cookie_value);
}

function getFavorites(){
	var favorites=new String();
	favorites=getCookies("favorites");
	return favorites;
}

function deleteCookie(cookie){
	exp = new Date(); 
	exp.setTime(exp.getTime() - 1800000);
	setCookie(cookie, '', exp, false, false, false);
	//document.location.reload();
}
	
function setCookie(name, value, expires, path, domain, secure) { 
	 var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	 document.cookie = curCookie;
}



	
function setMySize(size){
	var exp = new Date(); 
	exp.setTime(exp.getTime() + 18000000000000);
	deleteCookie("fontsize");
	setCookie("fontSize", size, exp, "/", window.location.hostname, "");
}

 ns4 = document.layers;
 ie = document.all;
 ns6 = document.getElementById && !document.all;
 
 
function changeStyles (size) {
 	var id='story_text';
    if (ns4) {
       alert ("Sorry, but NS4 does not allow font changes.");
       return false;
    }
    else if (ie) {
	   setMySize(size);
       obj = document.all[id];
    }
    else if (ns6) {
	   setMySize(size);
       obj = document.getElementById(id);
    }
    if (!obj) {
       alert("unrecognized ID");
       return false;
    }
	
	if(size=='small'){
    	obj.style.fontSize = "10px";
	}
	if(size=='medium'){
		obj.style.fontSize = "12px";
	}
	if(size=='large'){
		obj.style.fontSize = "15px";
	}
	
	//setMySize(size)
	
    return true;
 }

function getUser(){
	var user_vars;
	var name;
	if(GetCookie('personal')){
	  user_vars=GetCookie('personal').split("|");
	  name=user_vars[0].substr(0,7);
	}else{
	  name='<a href="/registration/login">log in</a>';
	}
	
	document.write(name);
}	
	
	
	
	
	
	var customarray=new Array('alaska','moose','moose hunting','moose killing','moose eating','anchorage','anchorage businesses','kingcup','kingdom','kingfisher','kingpin');
	
	function checkNS6(id,newclass){
		var navArray=navigator.userAgent.split(' ');
		if(navArray[(navArray.length-1)]=="Netscape6/6.2.3"){
			changeClass(id,newclass);
		}
	}
	
	function changeClass(id, newClass) {
		identity=document.getElementById(id);
		identity.className=newClass;
	}
	
	function setMyTab(id,tab){
		var exp = new Date(); 
		exp.setTime(exp.getTime() + 18000000000000);
		/*setCookie(id, tab, exp, "", "", "");*/
	}
	
	// Function which actually swaps tabs
	function changeTab (id,tabname) {
		
		var x=0;
		for(var i=1; document.getElementById(id+'_tab_t'+i); i++ ){
			//set all content areas to none
			document.getElementById(id+'_tab_t'+i).style.display = 'none';
			var tab='t'+i;
			
			//see if this iteration is the selected tab
			if(tabname==tab){
				changeClass(id+'_'+tab,'current');
				x=i-1;
				var prev='t'+x;
			}else{
				changeClass(id+'_'+tab,'none');
			}
		}
		if(x>0){changeClass(id+'_'+prev,'neighbor')}
		if(tabname!=tab){
			changeClass(id+'_'+tab,'last');
		}
		document.getElementById(id+'_tab_'+tabname).style.display = 'block';
		
		
	}

var start=1;
var end=5;
function setBlocks(start,end, parent_id){
	for(var s=start; s<=end; s++){
		if(document.getElementById(parent_id+s)){
			document.getElementById(parent_id+s).style.display="block";
		}
	}
}

function pageFlip(set,start,parent_id,no_count){//set is how many items are in each set
	var id="";
	var disp="";//what current id's display is 
	var b=0;
	var shown="";
	for(var i=1; document.getElementById(parent_id+i); i++ ){
		id=parent_id+i;
		y=document.getElementById(id);
		disp=y.style.display;
		y.style.display="none"
		if(disp=="block"){b=i;b++;}
	}
	if(start==1){
		b=Math.round(Math.random()*i);
	}
	var end=b+(set);
	if(b == i){
		end=set;
		setBlocks(1,end, parent_id);
		b=1;
	}else if(b == 0){
		end=set;
		setBlocks(1,end, parent_id);
		b=1;
	}else{
		end--;
		setBlocks(b,end, parent_id);
	}
	i--;
	if(end>i){end=i;}
	if(b==end){shown=b;}else{shown=b + '-' + end;}
	if(no_count){
		document.getElementById(parent_id + '_counter').childNodes[0].nodeValue ='next';
	}else{
		document.getElementById(parent_id + '_counter').childNodes[0].nodeValue = shown + ' of ' + i;
	}
}
// Popup

var popGallery = null;

function story_gallery(url)
{
	if (popGallery && !popGallery.closed)
		popGallery.location.href = url;
	else
		popGallery = window.open(url,'popGallery','height=500,width=350,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popGallery.focus();
	return false;
}

var popInfo = null;

function info_box(url)
{
	if (popInfo && !popInfo.closed)
		popInfo.location.href = url;
	else
		popInfo = window.open(url,'popInfo','height=300,width=420,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popInfo.focus();
	return false;
}

var popStory = null;

function print_story(url)
{
	if (popStory && !popStory.closed)
		popStory.location.href = url;
	else
		popStory = window.open(url,'popStory','height=600,width=590,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popStory.focus();
	return false;
}

var popWide = null;

function short_wide(url)
{
	if (popWide && !popWide.closed)
		popWide.location.href = url;
	else
		popWide = window.open(url,'popWide','height=415,width=625,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popWide.focus();
	return false;
}

var popJob = null;

function top_job(ref)
{
	var url=ref.href;
	if (popJob && !popJob.closed)
		popJob.location.href = url;
	else
		popJob = window.open(url,'popJob','height=540,width=540,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popJob.focus();
	return false;
}

var popEnlarge = null;

function enlarge(ref)
{
	var url=ref.href;
	if (popEnlarge && !popEnlarge.closed)
		popEnlarge.location.href = url;
	else
		popEnlarge = window.open(url,'popEnlarge','height=540,width=540,resizable=yes,toolbar=no,location=no');
	popEnlarge.focus();
	return false;
}

var popSized = null;

function popup_sized(url,height,width)
{
	if (popSized && !popSized.closed)
		popSized.location.href = url;
	else
		popSized = window.open(url,'popSized','height='+height+',width='+width+',resizable=yes,toolbar=no,location=no');
	popSized.focus();
	return false;
}

var popSizedScrl = null;

function popup_sized_scroll(url,height,width)
{
	if (popSizedScrl && !popSizedScrl.closed)
		popSizedScrl.location.href = url;
	else
		popSizedScrl = window.open(url,'popSizedScrl','height='+height+',width='+width+',scrollbars=yes,resizable=yes,toolbar=no,location=no');
	popSizedScrl.focus();
	return false;
}


function goGallery(url)  {
	galleryWindow = window.open(url,'gallerypopup','status=yes,width=600,height=600,scrollbars=auto,resizable=yes');
}

function jump_to(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* this function allows us to track clicks on links that have other onclick functionalit.. bstone@adn.com 4/28/05 */
function record_click(name,ref){
s_linkType="o";
s_linkName=name;
s_links_lnk=ref;
setTimeout("s_gs('nmanchorage')",0);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//for ie mac and win ie 5.0
//function borrowed from
//http://www.howtocreate.co.uk/emails/PhilipGreen.html
// to add push(), shift(),unshift(),pop(),splice(),slice() and concat() functions to older browsers (ie mac and win ie 5.0)
//thank you philip green
var testArray = new Array();
if(testArray.push){Array.prototype.push=function(){for(var i=0;i<arguments.length;++i){this[this.length]=arguments[i];}return this.length;};}
if(testArray.pop){Array.prototype.pop=function(){var r=null;if(this.length){r=this[this.length-1];--this.length;}return r;};}
if(testArray.copy){Array.prototype.copy=function(){var a=[];for(var i=0;i<this.length;++i){a[i]=this[i].copy?this[i].copy():this[i];}return a;};}
if(testArray.concat){Array.prototype.concat=function(a){var b=this.copy();for(var i=0;i<a.length;++i){b.push(a[i]);}return b;};}
//if(testArray.reverse){Array.prototype.reverse=function(){var a=[],i=this.length;while(i>0){a.push(this[--i]);}return a;};}
if(testArray.shift){Array.prototype.shift=function(){var r=null;if(this.length){r=this.reverse().pop();this.reverse();}return r;};}
if(testArray.unshift){Array.prototype.unshift=function(){this.reverse();for(var i=0;i<arguments.length;++i){this.push(arguments[i]);}this.reverse();return this.length;};}
if(testArray.splice){Array.prototype.splice=function(b,d){var m=b+d,af=this.slice(m),r=d>0?this.slice(b,m-1):[];for(var i=2;i<arguments.length;++i){af.unshift(arguments[i]);}
if(b>0){this.slice(0,b).concat(af);}else{while(this.length){this.pop();}while(af.length){this.push(af.pop());}}return r;};
}
