
var timages = new Array();


/**
* scroll script
*/

$(function(){

	$('a[href^=#]').click(function(){
		var $target = $(this.hash);
		var yy = (!isApple) ? $target.offset().top : $target.offset().top - window.scrollY;

		if (!isApple) {
			$($.browser.opera ? document.compatMode == 'BackCompat' ? 'body' : 'html' : 'html, body').animate({scrollTop: yy}, 300);
		}
		else {
			return true;
		}

		return false;
	});

/*
	if (document.getElementById("topimage")) {
		timages[0] = new Image();
		timages[0].src = "/images/phonegrafer/mainimage1.jpg";
		timages[1] = new Image();
		$(timages[1]).load(function() { initialized(); });
		timages[1].src = "/images/phonegrafer/mainimage2.jpg";
	}
*/

});


var timerId = -1;
var imageTurn = 0;

function initialized () {
	timerId = setTimeout(initialized2, 100);
}

function initialized2 () {
	stopTimer();
	document.getElementById("topimage").style.backgroundImage = "url(/images/phonegrafer/mainimage2.jpg)";
	timerId = setTimeout(doFade, 4000);
}

function startTimer () {
	timerId = setTimeout(startTimerb, 1000);
}

function startTimerb () {
	stopTimer();

	if (imageTurn == 0) {
		document.getElementById("topimage").style.backgroundImage = "url(/images/phonegrafer/mainimage2.jpg)";
	}
	else {
		document.getElementById("topimage").style.backgroundImage = "url(/images/phonegrafer/mainimage1.jpg)";
	}

	timerId = setTimeout(doFade, 4000);
}

function startTimer2 () {
	stopTimer();

	if (imageTurn == 1) {
		document.getElementById("imagebase").src = timages[0].src;
		$('#imagebase').fadeIn(0);
	}
	else {
		document.getElementById("imagebase").src = timages[1].src;
		$('#imagebase').fadeIn(0);
	}

	imageTurn++;
	if (imageTurn == 2) imageTurn = 0;

	startTimer();
}
function stopTimer () {
	if (timerId != -1) clearTimeout(timerId);
}
function doFade () {
	stopTimer();
	$('#imagebase').fadeOut(2000);
	timerId = setTimeout(startTimer2, 2010);
}




