$(document).ready(function() {
	$('#mainnav, #mainnav2').hide();
	// vars
	var hTimer = null;
	var my_url = document.URL;
	var my_gallery = my_url.search('gallery');
	var my_sequence = my_url.search('seq');
	var my_caption = my_url.search('/de/');

  /*image preloader
  $.preload( '#manual_view img', {//the first argument is a selector to the images
   //onRequest:request_manual,
    // onComplete:complete,
    //onFinish:finish_manual,
    placeholder:'/images/tools/kringel.gif',//this is the really important option
    notFound:'/images/tools/notfound.jpg',//optional image if an image wasn't found
    threshold: 2 //'2' is the default, how many at a time, to load.
    
	});
	  //not used
	function request_manual(){//hide the summary
    $('#manual_view img').attr('width', '220').attr('height','19');    
  };
	  //not used
	  function finish_manual(){//hide the summary
    $('#manual_view img').attr('width', '504').attr('height', '336');		
  };
	
	  $.preload( '#image_div_main img', {//the first argument is a selector to the images
   // onRequest:request_image,
    // onComplete:complete,
    //onFinish:finish_image,
    placeholder:'/images/tools/kringel.gif',//this is the really important option
    notFound:'/images/tools/notfound.jpg',//optional image if an image wasn't found
    threshold: 2 //'2' is the default, how many at a time, to load.
    
  });
	*/
  //not used
  function request_image(){//hide the summary
    $('#image_div_main img').attr('width', '220').attr('height','19');    
  };
  //not used
    function finish_image(){//hide the summary
    $('#image_div_main img').attr('width', '504').attr('height', '336');   
  };






	$('.view_select,#view_over').show();
	$('.go_overview').removeAttr('href');

	if(my_gallery == -1){
		if(my_sequence >= 0){
			$('.move').hide();
		}

		$('#seq_gallery').hide();
		$('.toggle_fullsize').css('color','#999999').removeAttr('href');
	}else{
		//alert("hi");

		$('.toggle_gallery').css('color','#999999').removeAttr('href');
		if (my_caption == -1) {
		  $('#view_caption').html("Caption").css('color', '#999999');
	  }else{
			$('#view_caption').html("Bildtitel").css('color', '#999999');
		}
		setTimeout("$('#seq_gallery').show();", 300); 
    $('.move').show();
	}

	var my_banner = my_url.search('banner');
	if(my_banner >= 0){
		$('#mainview_caption').html('Banner');
	}



	var my_imprint =  my_url.search('imprint');
	if(my_imprint >=0){
		$('#mainview_caption').html('Imprint');
		my_imprint_de = my_url.search('/de/');
		if(my_imprint_de >= 0){
			$('#mainview_caption').html('Impressum');
		}
	}

	var my_licence = my_url.search('lic');
	if(my_licence >= 0){
		$('#mainview_caption').html('Licence');
		my_licence_de = my_url.search('/de/');
		if(my_licence_de >= 0){
			$('#mainview_caption').html('Lizenz');
		}
	}

	var my_licence = my_url.search('contact');
	if(my_licence >= 0){
		$('#mainview_caption').html('Contact');
		my_licence_de = my_url.search('/de/');
		if(my_licence_de >= 0){
			$('#mainview_caption').html('Kontaktformular');
		}
	}



	$('.vote_hover').hover(
		function(){

			var counter = $(this).attr('rel');
			var my_counter = my_url.search('/de/');
			if(my_counter < 0){
				$('#pagenav').append('<div class="votecounter">Votes: ' +counter+'</div>');
			}
			if(my_counter >= 0){
				$('#pagenav').append('<div class="votecounter">Anzahl der Stimmen: ' +counter+'</div>');
			}
		},function(){
			$('.votecounter').remove();
		});

//////////////////////////////////////////
// 					Sequence Script							//
/////////////////////////////////////////

	$('#view_selector').show().css("cursor","pointer");

	$('#view_caption').hover(
		function(){
		$('#info_text').addClass('my_viewable').show();
		$('#caption_text').addClass('my_viewable').show();
		$('#manual_view').removeClass('my_viewable').addClass('my_opacity');
	},function(){
		$('#info_text').hide();
		$('#caption_text').hide();
		$('#manual_view').removeClass('my_opacity').addClass('my_viewable');
	});

	$('#view_over').hover(
		function(){
		$('#info_text').addClass('my_viewable').show();
		$('#overview_text').addClass('my_viewable').show();
		$('#manual_view').removeClass('my_viewable').addClass('my_opacity');
		$('.move').removeClass('my_viewable').addClass('my_opacity');
	},function(){
		$('#info_text').hide();
		$('#overview_text').hide();
		$('#manual_view').removeClass('my_opacity').addClass('my_viewable');
		$('.move').removeClass('my_opacity').addClass('my_viewable');
	});

//////////////////////////////////////////
// 				End	Sequence  Script					//
/////////////////////////////////////////

//////////////////////////////////////////
// 				Modify DL Script    					//
/////////////////////////////////////////

	$('.dl_link').removeAttr('href').css('cursor','pointer').click(
		function(){
			var dllink = $(this).attr("res");
			$('#manual_view').addClass('my_opacity');
			$('#vote_text').show().addClass('my_viewable');
			setTimeout(function(){top.location.href = dllink}, 3000);
	});


//////////////////////////////////////////
// 				End	Modify DL Script  				//
/////////////////////////////////////////

//////////////////////////////////////////
// 					Vote Script									//
/////////////////////////////////////////

	//change link for vote to ajax call
	$('.nav_votefor').removeAttr('href').css('cursor','pointer').click(
		function(){
			var imgid = $(this).attr('rel');
			$.ajax({ 
				url: '/cgi-bin/vote.pl',
				data: "id=" + imgid ,
				success: function(msg){
					var myurl = document.URL;
					var mysearch = myurl.search('/de/');
					var numRand = Math.floor(Math.random()*101);
					var myredirect = '/de/current/vote/'+numRand;
					if(mysearch == -1){
						myredirect = '/current/vote/'+numRand;
					}
					$('.backtovote').hide();
					$('.view_selector').hide();
// 					$('#gallerywrap').addClass('opacity');
					$('#manual_view').addClass('my_opacity');
					$('#vote_text').show().addClass('my_viewable');
					$('.nav_votefor').hide();//css('visibility','visible');
					$('.act_votes').html(msg);
					setTimeout(function(){top.location.href = myredirect}, 5000);
					}
			});
		});

//////////////////////////////////////////
// 		End		Vote	 Script								//
/////////////////////////////////////////

//////////////////////////////////////////
// 					Startmenu Script						//
/////////////////////////////////////////

	$('#start_mainnav').css('cursor','pointer');


	// slide menu down and fade active picture away
	$('#start_mainnav').mouseover(function(){
		$('.footer_info').show();
		if(hTimer != null){
			window.clearTimeout(hTimer);
			hTimer = null;
		}
		$('#contentblock').removeClass('my_viewable').addClass('my_opacity');
		if ($.browser.msie) {
		  $('#mainnav, #mainnav2').show();
		} else {
		  $('#mainnav, #mainnav2').slideDown("slow");
		}
		//alert(6);
	});

$('#col1').mouseover(function(){
	   if(hTimer != null){
      window.clearTimeout(hTimer);
      hTimer = null;
    }
});

	// resets timer for slide + fadeback
// 	$('#col1,#start_mainnav').mouseover(function(){
// 
// 	});

	// slide + fadeback with given timer
	$('#start_mainnav,#col1_content').mouseout(function(){
		hTimer = window.setTimeout(function(){
					     if ($.browser.msie) {
					       $('#mainnav, #mainnav2').hide();
								 
					     } else {
					       $('#mainnav,#mainnav2').slideUp("slow");
					     }
/*			$('#contentblock').fadeTo('fast',1.0);*/
			$('#contentblock').removeClass('my_opacity').addClass('my_viewable');

		}, 2500);
	});
	//STOP// MENU CONTROL

$('#col1_content').html($('#col1_content').html() + $('#col3_content').html());


$('li.menu_entry').css('background-color','#1d1d1d');
	// Menu hover effect
	$('li.menu_entry').hover(
		function(){
		$(this).css('background-color','rgb(75,75,75)');
	},function(){
		$(this).animate({
			backgroundColor: 'rgb(29,29,29)'
 		},550);
	});
//$('#mainnav2,#mainnav').css('background-color','#1d1d1d');


$('#col3_content').append($('#mapcontrol').html());
$('#mapcontrol').hide();

$('.maplink').removeAttr('href').css("cursor","pointer");
$('.maplink').click(function(){
  jumpto($(this).attr('rel'));
}).removeAttr("target");




//////////////////////////////////////////
// 		End		Startmenu Script						//
/////////////////////////////////////////

});
