var lastChangeFromFlash;



function anchorFromFlash(newAnch){	
	if(lastChangeFromFlash != newAnch){
		lastChangeFromFlash = newAnch;
		$.hash.go(newAnch);

		
	}
}

function getURLBase(partid) {

var myregexp = /^(http:\/\/.*?)\/([^#]*)#{0,1}(.*?)$/;
var match = myregexp.exec(location);
if (match != null) {
	result = match[partid];
} else {
	result = "";
}

return result;


}


function anchorListener(e, newHash) {
        
	if(lastChangeFromFlash != newHash ){
		if (newHash != '' && newHash != undefined) {
			if (newHash.match(/^.*_([0-9]+)\.html$/i)) {
				//alert("prod");
				lastChangeFromFlash = newHash;
				setFlashVar('showingAnchor',newHash);
				setFlashVar('openItemID',newHash.replace(/^.*_([0-9]+)\.html$/ig,"$1"));
			}
			
			if(newHash.match(/^.*_([0-9]+)_([0-9]+)$/i)){
				lastChangeFromFlash = newHash;
				setFlashVar('showingAnchor',newHash);
				setFlashVar('pageIndexOpen',newHash.replace(/^.*_([0-9]+)_([0-9]+)$/ig,"$2")/10);
				setFlashVar('openMenuID',newHash.replace(/^.*_([0-9]+)_([0-9]+)$/ig,"$1"));
				//alert(newHash.replace(/^.*_([0-9]+)_([0-9]+)$/ig,"$1"));
				//alert(newHash.replace(/^.*_([0-9]+)_([0-9]+)$/ig,"$2"));
			}

			if(newHash.match(/^q=(.*)_([0-9]+)$/i)){
				lastChangeFromFlash = newHash;
				setFlashVar('showingAnchor',newHash);
				setFlashVar('pageIndexOpen',newHash.replace(/^q=(.*)_([0-9]+)$/ig,"$2")/10);
				setFlashVar('searchQuery',newHash.replace(/^q=(.*)_([0-9]+)$/ig,"$1"));
			}

				
		} 
		else if(newHash == ''){
						
			if(lastChangeFromFlash == undefined){
				
				lastChangeFromFlash = '';
				$.hash.go('');

			} else {
							
				lastChangeFromFlash = newHash;
				setFlashVar('showingAnchor','');
				setFlashVar('openItemID','');
			}
			
		}
	}	
}

function getCurHash() {
    var index = location.href.indexOf('#');
    return (index == -1 ? '' : location.href.substr(index + 1));
}

function initHashAnchors(){

	if(getCurHash() != undefined && getCurHash() != ''){
		document.location.href = getURLBase(1) + "/" + getURLBase(3); 	
	}

	if (navigator.appName.indexOf("Microsoft") != -1){
		if(getCurHash() == undefined || getCurHash() == ''){
			location.replace(getURLBase(1) + "/" + getURLBase(2) + "#");
		 }
	}

	 $(window).hashchange(anchorListener);
	 $.hash.init('js/blank.html');
  	 
	
	
}






function findFlash(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1 && window[movieName] != undefined && typeof(window[movieName]) != 'undefined') {
        return window[movieName];
    }
    else {
	if(document[movieName] != undefined && typeof(document[movieName]) != 'undefined'){
        	return document[movieName];
	} else {
		return document.getElementById(movieName);
	}
    }
}


function setFlashVar(varName,varValue){
	
	findFlash('flashmovie').SetVariable(varName,varValue);
}


initHashAnchors();

