
$(function() {
		   
	getRandom = function rand (min, max) {
		return Math.floor(Math.random() * (max - min + 1)) + min;
	}
	
	jOpener = $('#opener');	
	jSkipOpener = $('#skip_opener');
	jOpenerText = $('#opener_text');	
	/*
	jOpenerText1 = $('#opener_text_1');
	jOpenerText2 = $('#opener_text_2');
	*/
	
	jOpenerStart = $('#opener_start');
	jOpenerImg1 = $('#opener_img_1');
	jOpenerImg2 = $('#opener_img_2');
	
	var randomImg = getRandom(1, 4);
    jOpenerImg1.find('img').attr('src', 'images/opener/opener_' + randomImg + '_1.jpg');
    jOpenerImg2.find('img').attr('src', 'images/opener/opener_' + randomImg + '_2.jpg');
	
	openerFinished = function() {
		jOpener.fadeOut('slow', function() {});
	}
	checkOpenerText = function(sec) {
		/*
		if (sec == 4) {
			jOpenerText1.fadeOut('slow', function() {
				jOpenerText2.fadeIn('slow', function() {});				
			});
		}
		*/
		if (sec == 5) {		
			jOpenerText.fadeOut('slow', function() {});
			jOpenerImg1.fadeIn('slow', function() {});
		}
		if (sec == 3) {
			jOpenerImg2.fadeIn('slow', function() {
				jOpenerImg1.fadeOut('slow', function() {});				
			});
		}
	}

	jSkipOpener.click(function() {
		openerFinished();					
	});
		
	jOpenerImg1.click(function() {
		openerFinished();					
	});		
	jOpenerImg2.click(function() {
		openerFinished();					
	});
	
	jOpenerImg1.find('img').load(function() {
	  $('#opener_counter').html('02');
	  $('#opener_counter').spriteTimer({
		 'seconds': 6,
			everySecondCallback: function(sec) {
				if (sec >= 5)
					$('#opener_counter').html('0' + (sec - 5));
				checkOpenerText(sec);
			},
		 'isCountDown': true,
		 'callback': openerFinished
	  });
	});
	

	jShowInfo = $('#showInfo');		
	jShowInfo.click(function() {
		/*	
		$('.esign_detail').fadeIn('slow', function() {
			// Animation complete.
		});
		*/
		document.location.href = 'produktdetail'; 					
	});
	/*
	backButton = $("#backButton");		
	backButton.click( function () {
		$('.esign_detail').fadeOut('slow', function() {});					
	});
	closeButton = $("#closeDetail");		
	closeButton.click( function () {
		$('.esign_detail').fadeOut('slow', function() {});					
	});
	*/

	jAdmin = $('#adminZone');	
	jAdmin.mouseenter(function() {
		$('#admin').show();	
	});
	jAdmin.mouseleave(function() {
		$('#admin').hide();	
	});
	
	jIcon = $('#icon');
	jBigIcon = $('#bigIcon');		
	jIcon.click(function() {
		jBigIcon.show();
		$(this).hide();
		jBigIcon.animate(
			{width:"123px", height:"70px"}, 
			300, 
			"swing", 
			function() {
				$('#password').show();
				$('#button').show();
				$('#password').focus();
			}
		);	
	});
	
	jInput = $('.loginInput');
	jInput.focus(function() {
		text = $(this).get(0).value;		
		changed = false;
		$(this).keydown(function() {
			changed = true;
		});				
		$(this).blur(function() {
			if (!changed)
				$(this).get(0).value = text;
		});
		$(this).get(0).value = "";
	});
	
	jB2BButton = $('#b2blogin');
	jB2BButton.click(function() {
		user = $('#b2buser').get(0).value;
		if (user == 'Benutzername') {
			alert(unescape("Bitte f%FCllen Sie alle Felder aus%21"));
			return false;
		}
	});
		
	jKeyword = $('#keyword');
	if ((jKeyword.length > 0) && (jKeyword.get(0).value != ""))
		$('#content_inner').highlight(jKeyword.get(0).value);
	jKeyword.focus(function() {
		var acttext = $(this).get(0).value;		
		changed = false;
		$(this).keydown(function() {
			changed = true;
		});				
		$(this).blur(function() {
			if (!changed)
				$(this).get(0).value = acttext;
		});
		$(this).get(0).value = "";
	});
	
	
	/*
	
	$('#newnews').click( function() {
		var now = new Date();
		var newurl = 'news_'+now.getFullYear()+now.getMonth()+now.getDate()+now.getHours()+now.getMinutes();
		document.location.href='index.php?url='+newurl; 
	});
	
	$('.fbname').mouseenter( function() {
		var pic_id = 'pic_'+this.id;
		$('#'+pic_id).show();
	});
	
	$('.fbname').mouseleave( function() {
		var pic_id = 'pic_'+this.id;
		$('#'+pic_id).hide();
	});
	
	var uploadAreas = $('.upload');
	for (i = 0; i < uploadAreas.length; i ++) {		
		page_id = uploadAreas[i].id;
		
		new AjaxUpload(page_id, {
			action: 'ajax.php', 
			data: {action: 'upload', pageId: page_id}, 
			onComplete: reloadPicture
		});	
	}
	
	$('.showhideNews').dblclick( function(){
		$.ajax({
			type: "POST",
	   		url: "/ajax.php",
		   	data: "action=showhideNews&id="+this.id,
		   	success: function(msg){
		   		params = msg.split('.');
		   		newsID = params[0];
		   		if(params[1] == 1) $('#'+params[0]).html('<img src="images/icons/green.gif">');
		   		else $('#'+params[0]).html('<img src="images/icons/red.gif">');
			}
		});
	});
	
	$('.showhideMembers').dblclick( function(){
		$.ajax({
			type: "POST",
	   		url: "/ajax.php",
		   	data: "action=showhideMembers&id="+this.id,
		   	success: function(msg){
		   		params = msg.split('.');
		   		newsID = params[0];
		   		if(params[1] == 1) $('#'+params[0]).html('<img src="images/icons/green.gif">');
		   		else $('#'+params[0]).html('<img src="images/icons/red.gif">');
			}
		});
	});
	*/	
	
});

/*
function reloadPicture(){
	$.ajax({
		type: "POST",
	   	url: "/ajax.php",
	   	data: "action=getNewsID",
	   	success: function(msg){
	   	if(msg == 'wff') alert('Sorry!\nBitte nur JPG Bilder verwenden.');
	   	else $('#'+msg).html("<img src=images/news/news_"+msg+"_new.jpg>");
		}
	});
}

function fbconnect(){
	$.ajax({
	   type: "POST",
	   url: "/ajax.php",
	   data: "action=fbconnect",
	   success: function(msg){
		 $('#user').html("Hallo <fb:name uid="+msg+" useyou=\"false\"></fb:name> du bist mit Facebook verbunden!"); 
	   	 $('#footer_right').html("<a href=\"#\" onclick='FB.Connect.logoutAndRedirect(\"/index.php\")'>Logout</a>");
         FB.XFBML.Host.parseDomTree();
	   }
	});
}
*/
