
$(document).ajaxError(function(){
    if (window.console && window.console.error) {
        console.error(arguments);
    }
});


$(function() {      

	$("#menu-items a, #startlink a").click(function() {

        // reset menu
         $('#menu-items li').each(function() {
	       imgid = $(this).attr('class').split('-');
	       imgid = imgid[1];

	       $(this).find('a').css('background-image', "url('http://www.northinteractive.de/fileadmin/templates/images/menupics/0"+imgid+"_n.gif')");
		 });
				  
		//fade out
		  $('#ajax-loader').show();
		  $('div.item').fadeTo(FADE_DELAY,0);
		  $('#main').fadeTo(FADE_DELAY,0);
	      $('a.prev, a.next').hide();
		// load content
		  pid = $(this).attr('href').split('=');
		  pid = pid[1];

		  if (pid == 3 | pid==4 || pid==10 || pid==11 || pid==12 || pid==13) {
			  loadContent(pid);	

			// set menu
			  imgid = $(this).parent().attr('class').split('-');
			  imgid = imgid[1];
			  menuitem = '.item-'+imgid+' a';
	          $(menuitem).css('background-image', "url('http://www.northinteractive.de/fileadmin/templates/images/menupics/0"+imgid+"_h.gif')");

			  return false;
		  }

	 });  		

	 $('#ajax-loader').show();
	 $('#main').css('opacity', '0');
	 $('#main').css('visibility', 'visible');
	
    if (PID==4 || PID==10 || PID==11 || PID==12 || PID==13) {   

	  loadContent(PID);	
    } else {   

	  $('#main').fadeTo(FADE_DELAY,1,function() {
		$('#ajax-loader').hide();
	  });	
	}
});

function loadContent(id) {

      call = AJAX_URL + '&id=' + id;

	  $.post( call, {},
			  function(response)
			  {
				 response = response.substr(0, response.length-1);

				 $('#main').fadeTo(0, 0);
				 $('div.item').fadeTo(0, 0);
				
		         $('#main').html(response);
			     
			     $('#main').css('background', 'none');
		
				 $('#main').fadeTo(0, 0);
				 $('div.item').fadeTo(0, 0);
				
			     initFlow();

			   	 $('#thumbs img').tooltip({ 
					position: ['center', 'center'],
					offset: [-100,0]
				    //opacity: 0.9
			   	 });

				 $('#main').fadeTo(1000, 0);
				 $('div.item').fadeTo(1000, 0);
				 $('#main').css('visibility', 'visible');
				 $('#main').fadeTo(FADE_DELAY, 1);
				 $('div.item').fadeTo(FADE_DELAY, 1, function() {
					$('#ajax-loader').hide();
				 });
					
								
				 
			  });
};

function initFlow() {
    $("div.scrollable").scrollable({ 							   
        size: 1, 
   //     easing : 'swing',
        items: '#thumbs',   
        hoverClass: 'hover',
        speed: 600
    });
}

