// Gido Carper www.jingho.de
// copyright 2009

var ContentL = document.getElementById('Content-Left');


var old_locations = "index";
var loadedPages = ",0,";


var loadedReferences = "";

var Languages = [];
Languages[1] = "de";
Languages[2] = "en";

var language = 1;

var ajaxObjectArray =[];
var pageHistory = [];

var AllPages = [];
AllPages[0] = 'index';
AllPages[1] = 'references';
AllPages[2] = 'vita';
AllPages[3] = 'contact';
AllPages[4] = 'editorial';
AllPages[5] = 'fischen';

var AllPagesNames = [];
AllPagesNames[1] = new Array(5);
AllPagesNames[1][0] = 'Startseite';
AllPagesNames[1][1] = 'Refrenzen';
AllPagesNames[1][2] = 'Lebenslauf';
AllPagesNames[1][3] = 'Kontakt';
AllPagesNames[1][4] = 'Impressum';
AllPagesNames[1][5] = 'Fischen';
AllPagesNames[1][6] = 'Blog';

AllPagesNames[2] = new Array(6);
AllPagesNames[2][0] = 'Index';
AllPagesNames[2][1] = 'References';
AllPagesNames[2][2] = 'Vita';
AllPagesNames[2][3] = 'Contact';
AllPagesNames[2][4] = 'Editorial';
AllPagesNames[2][5] = 'Fish';
AllPagesNames[2][6] = 'Blog';

var SubTitel = [];
SubTitel[1] = ' | Gido Carper - Entwickler und Programmierer';
SubTitel[2] = ' | Gido Carper - development and programming';

var wwwroot = 'http://www.jingho.de/';

var visiblePage = GetPageNo(GetURL());

function GetURL()
{
	var TempVisiblePage = location.href.replace(wwwroot,'');
	var BracketsPosition = TempVisiblePage.indexOf('#');
	if (BracketsPosition>=0)
	{
		TempVisiblePage = TempVisiblePage.substr(BracketsPosition,(TempVisiblePage.length-BracketsPosition));
	}
	
	TempVisiblePage = TempVisiblePage.replace('#','');
	TempVisiblePage = TempVisiblePage.replace('.php','');

	if (TempVisiblePage.indexOf(Languages[2] +'_')>=0)
	{
		language = 2;
		TempVisiblePage = TempVisiblePage.replace('en_','');
	}
	else
	{
		language = 1;
		TempVisiblePage = TempVisiblePage.replace('de_','');
	}
	if (TempVisiblePage=='')
	{
		TempVisiblePage = AllPages[0];
	}
	return TempVisiblePage;
}

function GetPageNo(PageName)
{
	var allAllPages = AllPages.length;
	for (var i = 0; i<allAllPages; i++)
	{
		if (AllPages[i]==PageName)
		{
			return i;
			break;
		}
	}
}

function getWindowHeight() {
     var wh = (typeof(window.innerHeight)=='number')?window.innerHeight:(document.documentElement && document.documentElement.clientHeight)?document.documentElement.clientHeight:(document.body && document.body.clientHeight)?document.body.clientHeight:0;
     var ww = (typeof(window.innerWidth)=='number')?window.innerWidth:(document.documentElement && document.documentElement.clientWidth)?document.documentElement.clientWidth:(document.body && document.body.clientWidth)?document.body.clientWidth:0;
     return {h:wh, w:ww};
}

function LoadPage(PageNo,NoHistory)
{
	if (loadedPages.indexOf(',' + PageNo + ',')<0)
	{
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].requestFile = 'contents/' + Languages[language] + '_' + AllPages[PageNo] + '_content.php';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { ShowPage(ajaxIndex,PageNo); };	
		ajaxObjectArray[ajaxIndex].runAJAX();	
	}
	else
	{
		document.getElementById('ContentWrapper').scrollTop = '0';
		HighlightLink(PageNo);
		VisibilizePage(PageNo,NoHistory);

		//window.frames.IframeTracker.location.href = 'trackers/' + Languages[language] + '_' + AllPages[PageNo] + '.php'
	}
	
}
function tryInitialiseVideo()
{
	$("#jquery_jplayer_1").jPlayer({
		ready: function () {
			$(this).jPlayer("setMedia", {
				m4v: "http://www.jingho.de/fischen.m4v",
				poster: "http://www.jingho.de/fischen.jpg"
			});
		},
		ended: function (event) {
			$(this).jPlayer("play");
		},
		swfPath: "../js",
		supplied: "m4v, ogv"
	});
}
function SendForm()
{
	OffFoc();
	document.eingabe.submit();
}

function HighlightLink(LinkNo)
{
	var allLinks = aLink.length;
	for (var i = 0; i<allLinks; i++)
	{	
		if (LinkNo==i)
		{
			aLink[i].className = 'RedLink';
		}
		else
		{
			aLink[i].className = 'GreyLink';
		}
	}
	OffFoc();
}
function ShowPageTitel(PageNo,language)
{
	document.title = AllPagesNames[language][PageNo] + ' ' + SubTitel[language];
}

function VisibilizePage(PageNo,NoHistory)
{	
	visiblePage = PageNo;
	ShowPageTitel(PageNo,language);
	var windowHeight = getWindowHeight();
	var SeiteMenge = AllPages.length;
	for (var i = 0; i<SeiteMenge; i++)
	{ 
		if (i!=PageNo)
		{
			if (document.getElementById(AllPages[i]))
			{
				document.getElementById(AllPages[i]).style.display = 'none';
			}
		}
		else
		{
			if (document.getElementById(AllPages[i]))
			{
				document.getElementById(AllPages[i]).style.display = 'block';
			}
		}
	}
	if (!NoHistory)
	{
		addHistory(PageNo);
	}
}



function ShowPage(ajaxIndex,PageNo)
{
	document.getElementById('ContentWrapper').scrollTop = '0';
	//document.getElementById(AllPages[PageNo]).innerHTML = ajaxObjectArray[ajaxIndex].response;
	$('#'+AllPages[PageNo]).append(ajaxObjectArray[ajaxIndex].response);
	if (PageNo==5) tryInitialiseVideo();
	loadedPages += ',' + PageNo + ',';
	HighlightLink(PageNo);
	VisibilizePage(PageNo);
}

function OffFoc()
{
	if(navigator.userAgent.indexOf("MSIE") == -1) {
		document.getElementById('offocus').focus();
	}
}

var ReferenceOn = -1;

function hideReferences()
{	

	
	
	t1 = new Tween(document.getElementById('ref_Scr' +ReferenceOn).style,'top',Tween.regularEaseIn,90,1500,0.5,'px');
	t1.start();		
	t1.onMotionFinished = function()
	{
		document.getElementById('ref_Scr' +ReferenceOn).style.display = 'none';
		divContentWrapper.style.overflowY = 'auto';
		divContentWrapper.style.overflowX = 'hidden';	
		opacityTween = new OpacityTween(document.getElementById('ContentWrapperOverlay'),Tween.regularEaseOut, 65,0, 0.5);
		opacityTween.start();			
		divContentWrapperOverlay.style.display = 'none';
		
	};
}
function showReferences(RefNo)
{
	if (!Dragging)
	{
		if (loadedReferences.indexOf(',' + RefNo + ',')<0)
		{
			document.getElementById('ref_Scr' + RefNo + '_top').innerHTML = '<img src="/img/screenshots/scr' + RefNo + '.gif" width="525" height="337" alt="" style="margin-left:20px;margin-top:24px;"/><a href="javascript:hideReferences();"><img src="/img/screen/references/close.png" width="30" height="30" alt="" style="position:absolute;left:530px;top:10px;"/></a>';
			loadedReferences += ',' + RefNo + ',';
		}
		//window.frames.IframeTracker.location.href = 'trackers/' + language + '_references' + RefNo + '.php';

		divContentWrapperOverlay.style.display = 'block';
		divContentWrapper.style.overflowY = 'hidden';
		divContentWrapper.style.overflowX = 'hidden';

		opacityTween = new OpacityTween(document.getElementById('ContentWrapperOverlay'),Tween.regularEaseOut, 0,65, 0.5);
		opacityTween.start();

		opacityTween.onMotionFinished = function()
		{


			document.getElementById('ref_Scr' +RefNo).style.display = 'block';
			t1 = new Tween(document.getElementById('ref_Scr' +RefNo).style,'top',Tween.regularEaseIn,-500,90,0.75,'px');
			t1.start();	
			ReferenceOn = RefNo;



		};
	}
}
