var $to;
$(document).ready(function() {
		window.setInterval("slideRight()",5000);
		
		
		$('.sbItem').mouseStay({handler: function(){
			var $this = $(this);
			var temp1 = $this.attr('id').split('_');
			var id = parseInt(temp1[1]);
			
			//changeContent(id);
			
			for(var i = 0; i <= 8; i++){
				if(i < 8){
					if(i != id){
						$('#imgItem_' + i).animate({'opacity':'0.0'},'fast');
						}
					}else{$('#imgItem_' + id).animate({'opacity':'1.0'},'slow');}
				}
			},delayTime:200});
		
		$(".header").mouseleave(function(){
			$('.imgArea > img').animate({'opacity':'0.0'},2000);
			});
		
		$(".slider").mouseenter(function(){
			$("#autoInd").val(0);
			});
		$(".slider").mouseleave(function(){
			$("#autoInd").val(1);
			});
		
		$('.rModHead').click(function(){
			var $this = $(this);
			$("#rModBody_" + $this.attr('rel')).slideToggle('slow');
			});
		
		$("a.view").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'overlayShow'	:	false
				});	
				
		$(".fancyAnfahrt").click(function(){
			$.ajax({
				type	: "POST",
				cache	: false,
				url		: "ajax/mapsView.php",
				data		: $(this).serializeArray(),
				success: function(data) {
						$.fancybox(data);
					}
				});
			});
		if(ID != 0){
		$("#file_upload").uploadify({
			'uploader'    : 'uploadify/uploadify.swf',
			'script'      : 'uploadify/uploadify.php',
			'cancelImg'   : 'uploadify/cancel.png',
			'folder'      : 'uploads',
			'multi'       : true,
			'width'       : 191,
			'height'      : 27,
			'sizeLimit'   : 2000000,
			'buttonImg'   : 'uploadify/btnSelectImg_i.png',
			'scriptData'  : {
							'ID' :   ID
							},
			'onSelect'    : function(event,ID,fileObj){
								$('.btnExecuteUpload').fadeIn('slow');
								},
			'onAllComplete' : function(event,data) {
								  $('.infoImgUpload').css('border','1px solid #404040');
							  	  $('.infoImgUpload').html("Es wurde(n) " + data.filesUploaded + " Datei(en) erfolgreich auf den Server geladen <br />Es konnte(n) " + data.errors + " Datei(en) nicht auf den Server geladen werden <br />Das Datenvolumen aller Dateien betrug " + data.allBytesLoaded + " Bytes und wurde mit einer durchschnittlichen Geschwindigkeit von " + data.speed + " KB/s hochgeladen");
								  $.ajax({
									type: "POST", 
									url: "ajax/reloadImgArea.php", 
									data: "id=" + ID,
									success: function(data){
										$('.adminImgArea').html(data);
										initDeleteButtons();
										}
							  		});
									$('.btnExecuteUpload').fadeOut('slow');
								}
			});
		}
		
		
	initDeleteButtons();
	
	
	// Gallery
	
	var galleries = $('.ad-gallery').adGallery({
					loader_image: '../gallery/loader.gif',
					slideshow: {
						enable: false
						},
						effect: 'fade'
					});
				$('#switch-effect').change(
				  function() {
					galleries[0].settings.effect = $(this).val();
					return false;
				  }
				);
				$('#toggle-slideshow').click(
				  function() {
					galleries[0].slideshow.toggle();
					return false;
				  }
				);
				$('#toggle-description').click(
				  function() {
					if(!galleries[0].settings.description_wrapper) {
					  galleries[0].settings.description_wrapper = $('#descriptions');
					} else {
					  galleries[0].settings.description_wrapper = false;
					}
					return false;
				  }
				);
	
	
	$('#sockel').click(function(){
		if($('#imgSockel').css('width') == '143px'){
			$('#imgSockel').animate({'width':'460px'},'fast');
			}else{
				$('#imgSockel').animate({'width':'143px'},'fast');
				}
		});
		
	});





var $uc = 5;
function slideRight(){
	if($("#autoInd").val() == 1){
		$('.sliderRow').prepend("<div style='margin-left:0px;width:0px;' class='sdrItem'></div>");
		$('.sdrItem').eq(0).animate({'margin-left':'25px','width' : '300px'},
				{
				duration: 1000,
				specialEasing: {
								'margin-left' : 'linear',
								'width' : 'easeOutSine'
								}	
				,
				complete: function(){	
						$('.sdrItem').eq(4).fadeOut('slow',function(){	
						$(this).remove();
						});
					}
				});
					
			
			
			var $unitCount = $uc;
			var unitCount = $("#unit" + $unitCount).html();
			$('.sdrItem').eq(0).html(unitCount);
			
			var $newUnitCount = 0;
			if($unitCount < 7){
				$newUnitCount = $unitCount + 1;
				}else{
					$newUnitCount = 1;
					}
			
			$uc = $newUnitCount;
		}
	}
	

function initDeleteButtons(){
	$('.imgAdminPrevDelete').click(function(){
			$('.infoImgUpload').css('border','none').html('');
			var imgId = $(this).attr('rel');
			$.ajax({
				type: "POST", 
				url: "ajax/deleteImg.php", 
				data: "imgId=" + imgId + "&refId=" + ID,
				success: function(data){if(data != 0){
						$('.adminImgArea').html(data);
						initDeleteButtons();
						}else{
							$('.adminImgArea').html('keine Bilder');
							}
					}
				});
			});
	}	
	
