var destination;

// JavaScript Document
linkutil = new function() {
	// Deeplinks that should NOT be in history or cookie crumb
	this.noHistory = [
		//"/legacy_playback",
		//"/legacy_test"
	];
	
	// Find history value, since IE doesn't have indexOf ;p
	this.hasHistory = function( value ) {
		for( var i=0; i<this.noHistory.length; i++ ) {
			if( this.noHistory[i].indexOf(value) > -1 ) return false;
		}
		return true;
	}
	
	this.deeplink = function( link ) {
		// get path without query string
		var path = link.split("?")[0];
		if( this.hasHistory(path) ) {
			SWFAddress.setValue(link);
		// If not we have to do things manually so they don't get added to history
		} else {
			// Reference the swf
			var swf = document.getElementById( "shell" );
			// Circumvent SWFAddress
			swf.navigateTo(link);
		}
	}
	
	this.go = function( str ) {
		
		var i = str.indexOf(":");
		var type = str.slice(0,i);
		var link = str.slice(i+1).split("|");
		
		//if( console ) console.log("linkutil.go",str);
		
		switch( type ) {
			case "deeplink":
				var scrollDis = $('html').scrollTop();
				if( scrollDis > 0 ) {
					$('html').animate({scrollTop: 0}, 300, function() {
						linkutil.deeplink( link[0] );
					});
				} else {
					this.deeplink( link[0] );
				}
				break;
			case "url":
				location.href = link[0];
				break;
			case "javascript":
				eval(link[0]);
				break;
		}
	}
	
}
