/* 
 * Programiert von Christopher Weiß
 * copyright 2010
 * JS 2b-zone.de
 * Publisher: cweiss.info
*/

var slideTimer;
var userTimer;
clearImage = new Image(); 
clearImage.src = websiteUrl + "/images/menu_bb_rl.png";
clearImage.src = websiteUrl + "/images/menu_contact_rl.png";
clearImage.src = websiteUrl + "/images/menu_home_rl.png";
clearImage.src = websiteUrl + "/images/menu_portfolio_2d_rl.png";
clearImage.src = websiteUrl + "/images/menu_portfolio_3d_rl.png";
clearImage.src = websiteUrl + "/images/menu_portfolio_ani_rl.png";
clearImage.src = websiteUrl + "/images/menu_about_rl.png";
clearImage.src = websiteUrl + "/images/details_bg_rl.png";

$('.noscript').css({ 'display' : 'none' });

function changeInputFocus(defaultvalue, insertedvalue) {
	if(insertedvalue.value == defaultvalue) {
		insertedvalue.value = "";
	}
}
function changeInputBlur(defaultvalue, insertedvalue) {
	if(insertedvalue.value == "") {
		insertedvalue.value = defaultvalue;
	}
}

function changeAreaFocus(defaultvalue, insertedvalue) {
	if(insertedvalue.value == defaultvalue) {
		insertedvalue.value = "";
	}
}

function changeAreaBlur(defaultvalue, insertedvalue) {
	if(insertedvalue.value == "") {
		insertedvalue.value = defaultvalue;
	}
}
function scrollToHeadline (val) {
	$('html, body').stop()
	.animate({
		scrollTop: $(val).offset().top - 85
	}, 1500);
	return false;
}
function gotoPortfolio (val) {
	window.location.href = val;
	return false;
}
function details (val, div) {
	if ($(val).is(":hidden")) {
		var shorty = val.replace(/details/g, "detailsshort");
		$(shorty).css({'display' : 'none' });
		$(val).slideDown("fast");
		$(div).css({'background' : 'url(' + websiteUrl + '/images/details_bg_rl.png) bottom left no-repeat' });
	} else {
		var shorty = val.replace(/details/g, "detailsshort");
		$(val).slideUp("fast");
		$(shorty).show('fast');
		$(div).css({'background' : 'url(' + websiteUrl + '/images/details_bg.png) bottom left no-repeat' });
	}
}
function changeImage(val, from) {
	var allTabs = [];
	var a = [];
		i = 1;
	while (i <= 5) {
		allTabs.push('#preview-project-' + i);
		i = i + 1;
	}
	switch(val) {
		case '1':
			a.push("2","3","4","5");
			var b = 2;
			break;
		case '2':
			a.push("1","3","4","5");
			var b = 3;
			break;
		case '3':
			a.push("1","2","4","5");
			var b = 4;
			break;
		case '4':
			a.push("1","2","3","5");
			var b = 5;
			break;
		case '5':
			a.push("1","2","3","4");
			var b = 1;
			break;
	}
	var i = 0;
	while (i <= 3) {
		$('#preview-project-'+a[i]).attr('class', 'inactive-point');
		$('#preview-image-'+a[i]).hide();
	
		i = i+1;
	}
	$('#preview-project-'+val).attr('class', 'active-point');
	$('#preview-image-'+val).fadeTo("slow", 1);
	if(from=='0') { 
		clearTimeout(slideTimer);
		clearTimeout(userTimer);
		slideTimer = setTimeout("changeImage('" + b + "','0')", 5000); 
	} else if (from=='1') { 
		clearTimeout(userTimer);
		clearTimeout(slideTimer);
		userTimer = setTimeout("changeImage('" + b + "','0')", 10000); 
		
	}
}
function bannerTimer(val) {
	$('.menu img.bb').fadeTo('slow', 0, function(){
		switch(val) {
			case 'org': 
				$('.menu img.bb').attr('src', websiteUrl + '/images/menu_bb.png');
				setTimeout("bannerTimer('rl');", 3000);
				break;
			case 'rl':
				$('.menu img.bb').attr('src', websiteUrl + '/images/menu_bb_rl.png');
				setTimeout("bannerTimer('org');", 3000);
				break;
		}
		$('.menu img.bb').fadeTo('slow', 1);
	});
}
function loadImage (imageUrl, id) {
    var img = new Image();
    $(img).load(function () {
		$(id).hide();
		$(id).append(this);
		$(id).fadeIn();
    }).error(function () {
    }).attr('src', imageUrl);    
	return;
}
$(document).ready(function(){
	$(".noscript").css({'display' : 'none'});
	$(".detail-information").css({'display' : 'none'});
	$(".menu img").hover(function() {
		if($(this).attr('class')=='bb') { return false; }
		$(this).css({'z-index' : '10'});
		var test = this.src.replace(/.png/i, '_rl.png');
		$(this).css({'background' : 'url('+ test +') -140px 0px no-repeat'});
		$(this).stop()
		.animate({
			backgroundPosition: '0px 0px no-repeat'},
			{duration: 300});
	}, function() {
		$(this).removeAttr('style').stop();
	});
	if($('#preview-image-1').length != 0) {
		slideTimer = setTimeout("changeImage('2','0')", 5000)
	}
	setTimeout("bannerTimer('rl');", 3000);
	$("a.section-projects").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'fade',
		'speedIn'		: 300, 
		'speedOut'		: 100, 
		'overlayShow'	: true,
		'titlePosition' : 'over',
		'onComplete'	: function() {
			$("#fancybox-wrap").hover(function() {
				$("#fancybox-title").show();
			}, function() {
				$("#fancybox-title").hide();
			});
		}
	});
});
