$(document).ready(function() {
	var clicked = '';
	$('a','#sections').click(function() {
			clicked = $(this).attr('id');
			document.title = 'elektrogrill '+clicked;
	});	

	
	$('a','#sections').hover(
		function(){
			var section = $(this).attr('id');
  			document.getElementById('woman').style.backgroundImage = 'url(/images/frau_'+section+'.gif)';
			document.getElementById('img_'+section).src = '/images/'+section+'_black.gif';
		},function(){
			var section = $(this).attr("id");
			document.getElementById('img_'+section).src = '/images/'+section+'.gif';			
	});	
	
	$('#news').click(function() {
		get_content(clicked, 'scroll');
	});
	
	$('#photos').click(function(){
		if((navigator.platform) == 'MacPPC')
		{
			var overflow = $('#text_box').css('overflow');	
			$('#text_box').css('overflow','hidden');
		}
		loadLytebox('first');
	});
	
	$('#kontakt').click(function() {
		get_content(clicked, 'hidden');		
	});
	
	$('#links').click(function() {
		get_content(clicked, 'scroll');		
	});
	
	$('#newsletter').click(function() {
		get_content(clicked, 'hidden');		
	});

	
	$('#maps').click( function(){
			document.title = 'elektrogrill wegbeschreibung'
			get_content('map', 'scroll');
			window.open('/map.php',"karte",'height=450,width=700');
	});
	
	$('#maps').hover(
		function(){
  			document.getElementById('woman').style.backgroundImage = 'url(/images/frau_start.gif)';
		},function(){
 	 		
	});
	
});

function get_content(section, overflow)
{
	if($("#tree").css("display") == 'block')
	{
		$("#tree").fadeOut("slow", function(){
			open_text_box('text_'+section+'.png', section, overflow);
		});
	}
	else
	{
		$('#inner_text_box').fadeOut("slow", function(){
			$('#text_box').slideUp(1000, function(){
				open_text_box('text_'+section+'.png', section, overflow);
			});
		});
	}
}

function open_text_box(image, section, overflow){
	$('#text_box').css('background-image','url(/images/'+image+')');
	$('#text_box').empty();
	var html = $.ajax({
		url: "content.php?section="+section,
		async: false
	}).responseText;
	$('#text_box').slideDown(1000, function(){
		$(html).appendTo('#text_box');
		$('#inner_text_box').fadeIn("slow", function(){
				$('#text_box').css('overflow',overflow); 
					
		});
			
	});

}

function send_form(){
	var subscribe_status = ''
	if(document.getElementById('subscribe').checked == true){
		subscribe_status = 'subscribe';
	}
	else{
		subscribe_status = 'unsubscribe';
	}
	var email = document.getElementById('email').value;
	$.ajax({
  		type: "POST",
  		url: "content.php?section=newsletter",
  		data: "do="+subscribe_status+"&email="+email,
  		success: function(html){
  			$('#text_box').empty();
    		$(html).appendTo('#text_box');
    		$('#inner_text_box').css('display','block'); 
  		}
	});
}

function loadLytebox(id) {
    if (typeof myLytebox != 'undefined') {
        // if the myLytebox object exists, start it up!
        myLytebox.start(document.getElementById(id),true);
    } else {
        // wait 1/10th of a second and attempt loading again...
        if (timeoutID) { clearTimeout(timeoutID); }
        timeoutID = setTimeout('loadLytebox("'+id+'")', 100);
    }
}
