// Window Opening / Closing Funcitons 

function goLink(type,url,cat,pagename,overide){
	var concat = (url.indexOf('?') > 0) ? '&' : '?';
	var trackstr = "";//Remove the assignment of variables to this function
	if       (type==1){ // Center Window
		top.frames['main'].location = url + trackstr;
	} else if(type==2){ // Self window
		location.href = url + trackstr;
	} else if(type==3){ // Open blank window
		window.open(url+trackstr);
	} else if(type==4){ // Cisco Large Popup
		var url_to_launch = !overide ? url+trackstr : url;
		var popup = window.open(url_to_launch);
		if (popup) popup.focus();
	} else if(type==5){ // External links with exit page
		exitpage = 'exit.html';
		if(cat == 'work' || cat == 'live' || cat == 'play' || cat == 'learn') exitpage = 'exit_' + cat + '.html';
		var url_to_launch = !overide ? exitpage + '?url=' + escape(url+trackstr) : exitpage + '?url=' + escape(url);
		var popup = window.open(url_to_launch);
		if (popup) popup.focus();
	}
	return;
}

//flash nav
function goCenterLink(url){
//	top.frames['main'].location = url;
	goLink(1,url,'stories');
}

function openChildWindow( appurl, windowname ) {
  var appwindow = window.open( appurl , windowname, "toolbar=yes,status=yes,top=25,left=0,outerWidth=798,outerHeight=547,width=798,height=547,scrollbars=yes,resizable=yes,menubar=yes,locationbar=no,");
  if (appwindow) appwindow.focus();
}

function global_openCdcPopup ( url, width, height ) {
  if ( isNaN(parseInt(width)) ) { width=550; } 
  else { width=parseInt(width); }
  if ( isNaN(parseInt(height)) ) {height=550; }
  else { height=parseInt(height); }

  var windowparms = "status=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height;
  var popup = window.open ( url, "globalCDCpopup", windowparms);
  if (popup) popup.focus();
}

// This function openLargePopup is now deprecated. Please don't use.
function openLargePopup( url, windowname ) {
  var popup = window.open( url , windowname, "toolbar=yes,status=yes,scrollbars=yes,menubar=yes,locationbar=no,top=50,left=70,outerWidth=643,outerHeight=468,width=643,height=468,resizable=yes");
  if (popup) popup.focus();
}

// This function openMediumPopup is now deprecated. Please don't use.
function openMediumPopup( url, windowname ) {
  var popup = window.open( url , windowname, "toolbar=no,status=yes,scrollbars=yes,menubar=no,locationbar=no,top=90,left=170,outerWidth=445,outerHeight=390,width=445,height=390,resizable=yes");
  if (popup) popup.focus();
}

// This function openSmallPopup is now deprecated. Please don't use.
function openSmallPopup( url, windowname ) {
  var popup = window.open( url , windowname, "toolbar=no,status=yes,scrollbars=yes,menubar=no,locationbar=no,top=90,left=290,outerWidth=220,outerHeight=390,width=220,height=390,resizable=yes"); 
  if (popup) popup.focus();
}

function closeWindow() {
  self.close();
}

function QueryString_Object(URL){ // QueryString Object V1.0 developed by Guy Shahar, OgilvyInteractive, New York
	if(!URL){URL = location.href;} // If no argument, use the document URL
	this.raw = URL.substring(URL.indexOf('?')+1,URL.length); // Grab and store QueryString after the "?"
	this.Name = Array();
	this.Value = Array();
	QueryString_Object.prototype.Get = QueryString_Object_Get;
	
	var args = this.raw.split('&'); // Parse out the parameters separated by "&"
	
	for (var i=0;i<args.length;i++){ // Split out and store each name/value pair
		var pair = args[i].split('=');
	
		temp = unescape(pair[0]).split('+'); // Fix broken unescaping
		temp0 = temp.join(' ');
		
		temp = unescape(pair[1]).split('+');
		temp1 = temp.join(' ');
		
		this.Name[i] = temp0;
		this.Value[i] = temp1;
	}
}
function QueryString_Object_Get(what){ // Get the value based on the parameter name
	for (var i=0;i<this.Name.length;i++){
		if(this.Name[i] == what){
			return this.Value[i];
		}
	}
	return false; // return false if parameter doesn't exist
}

// Instantiate Object
var QueryString = new QueryString_Object();

function getObj(obj){
	if(document.layers){
		return document.layers[obj];
	} else if(document.all){
		return document.all[obj].style;
	} else {
		return document.getElementById(obj).style;
	}
}
/*function testObj(obj){
	if(document.layers){
		if(!document.layers[obj]){ return false;}
	} else if(document.all){
		if(!document.all[obj]){ return false;}
	} else {
		if(!document.getElementById(obj)){ return false;}
		return true;
	}
}*/
function show(what){getObj(what).visibility = "visible";}
function hide(what){getObj(what).visibility = "hidden";}
function showblock(what){getObj(what).display = "block";}
function hideblock(what){getObj(what).display = "none";}


// FADING MODULE PODS
function Pod(){
	this.ModuleCount = 1;
	this.ModuleDelay = 5;
	this.FadeSpeed = 50;
	this.FadeStep = 5;
	this.FadePos = 0;
	this.Last = 1;
	this.zCount = 1000;
	this.Name, this.LayerOn, this.LayerOff, this.FADEINT, this.MODINT;

	Pod.prototype.Start = Start;
	Pod.prototype.Controller = Controller;
	Pod.prototype.Fader = Fader;

	this.oid = 'oid_' + Pod.prototype._counter++;
 	eval(this.oid + '=this');
}
Pod.prototype._counter = 0;
function Start(){
	setTimeout(this.oid + '.Controller()', this.ModuleDelay*1000);
}
function Controller(){
	for(i=0;i<100;i++){
		var rnd = Math.floor(Math.random()*this.ModuleCount)+1;
		if(rnd != this.Last && rnd != 0){break;}
	}
	if(this.Last){
		this.LayerOff = 'mod-' + this.Name + '-0' + this.Last;
	}
	this.LayerOn = 'mod-' + this.Name + '-0' + rnd;
	show(this.LayerOn);
	setObjZ(this.LayerOn,1);
	setObjFade(this.LayerOn,100);
	this.FADEINT = setInterval(this.oid + '.Fader()',this.FadeSpeed);
	this.Last = rnd;
}
function Fader(){
	this.FadePos += this.FadeStep;
	if(this.FadePos < 100){
//		setObjFade(this.LayerOn,this.FadePos);
		setObjFade(this.LayerOff,(100-this.FadePos));
	} else {
		this.FadePos = 0;
		setObjFade(this.LayerOn,100);
		setObjZ(this.LayerOn,this.zCount++);
		setObjFade(this.LayerOff,0);
		setObjZ(this.LayerOff,1);
		hide(this.LayerOff);
		clearInterval(this.FADEINT);
		setTimeout(this.oid + '.Controller()',this.ModuleDelay * 1000);
	}
}

function setObjFade(obj,f){
	if(typeof document.getElementById(obj).style.filter != 'undefined'){
		document.all[obj].style.filter = "alpha(opacity="+f+")";;
	} else if(typeof document.getElementById(obj).style.opacity != 'undefined'){
		document.getElementById(obj).style.opacity = f/100;
	}
}
function setObjZ(obj,z){
	if(typeof document.getElementById(obj).style.filter != 'undefined'){
		document.all[obj].style.zIndex = z;
	} else if(typeof document.getElementById(obj).style.opacity != 'undefined'){
		document.getElementById(obj).style.zIndex = z;
	}
}

function endflash(){
	// 
}

function vs_makeurl(vars) {
  var method = "GET";
  var cd = "http://www.cisco.com";
  var cu = "/swa/j/zag2_vs_log1.asc?Log=1";
  var cb = "&cb=" + (new Date()).getTime();
  var url = cd + cu + vars + cb;
  var imObj = new Image();
  imObj.src = url;
  return true;
}

function vs_trackemail(){
	vs_makeurl('&pcontent=hn_us&pagename=human_network&flash_destination=email');
}
function vs_trackflash(cat, pagename){
	vs_makeurl('&cat='+cat+'&pagename='+pagename);
}
function vs_trackflashtest(cat, pagename){
	vs_makeurl('&pcontent=hn_us'+'&cat='+cat+'&pagename='+pagename);
}


// Curent Story Number
var URL = document.URL;
var story_num = URL.substring(URL.indexOf('.html') - 2, URL.indexOf('.html'))

function send_story_2friend(pagename){
//	vs_makeurl('&pcontent=hn_us&pagename=' + escape(pagename) + '&flash_destination=email');
	vs_trackemail();
	snum = story_num;
	if(snum.charAt(0) == '0'){snum = snum.charAt(1);}
	location.href = 'mailto:?subject=You%20should%20read%20this&body=Check%20out%20this%20story%20I%20found%20on%20the%20Cisco%20human%20network%20site.%20It%27s%20a%20really%20great%20example%20of%20how%20the%20network%20can%20help%20regular%20people%20accomplish%20pretty%20much%20anything.%0A%0ARead%20story%20at%3A%0Ahttp%3A//www.cisco.com/go/story' + snum;
	
}

function send_site2friend(){
	var str = "mailto:";
	str += "?subject=" + escape("human network un sito da vedere");
	str += "&body=" + escape("ho scoperto il sito Cisco dedicato alla human network. Non e un sito pubblicitario, ma uno spazio aperto al contributo di tutti. \n\nContiene le esperienze delle persone che hanno usato la rete per creare cose straordinarie e interagire con altri in tutto il mondo. E mostra come la human network cambia il nostro modo di vivere, lavorare, imparare, divertirci.\n\nGuardalo anche tu, all indirizzo \n\nhttp://www.cisco.com/it/humannetwork/");
	location.href = str;
	vs_trackemail();
}