var ajaxBase;
//ajaxBase = "/projects/rohrer.biz/core/components/stage/ajax/";
ajaxBase = "/core/components/stage/ajax/";

function activateSort(objectID) {
	var oldClass = $("#sortable").attr("class");
	if(oldClass) {
		oldClass = oldClass.split(" ");
		oldClass = oldClass[0];
		$("#sortable").attr("class", oldClass);
	}
	$("#sortable").attr("id", "");
	var mySortContainer = ".sortme_"+objectID;
	$(mySortContainer).attr("id", "sortable");

	$('#sortable').sortable({
	revert: true,
	update: function () {
	var order = $('#sortable').sortable('serialize');	

	$.get(ajaxBase+'sortlogos.php', { sortorder: order },
	function(data){ $('#msgcontainer').prepend(data); styleMessages(); });
	
	}});
	$('#sortable').disableSelection();

}


function editFotoText(fotoID) {
	$('#form-object-foto-title-edit').val("");
	$('#form-object-foto-desc-edit').val("");
	$('#form-object-foto-hidden-edit').val(fotoID);
	$.get(ajaxBase + "editFotoText.php", { myFotoID: fotoID, mode: "get" },
   function(data){
	var ajaxRet = new Array();
     eval(data);
	 $('#form-object-foto-title-edit').val(ajaxRet[0]);
	 $('#form-object-foto-desc-edit').val(ajaxRet[1]);
	 $('#stage-edit-foto-frame').fadeIn();
   });
}

function saveFotoText(fotoID) {
	$.get(ajaxBase + "editFotoText.php", { 
											myFotoID: fotoID,
											mode: "set",
											myTitle: $('#form-object-foto-title-edit').val(),
											myDesc: $('#form-object-foto-desc-edit').val(),
											},
	function(data){ 
		updateFotoItem(fotoID);
		$('#stage-edit-foto-frame').fadeOut();
		}
	);
}

function updateFotoItem(fotoID) {
	var objFoto = "#foto_"+fotoID;
	$.get(ajaxBase + "editFotoText.php", { myFotoID: fotoID, mode: "update" },
   function(data){
		if(data != "") {
			$(objFoto).find("h3").text(data);
		}
   });
}

function deleteFoto(fotoID) {
	var objFoto = "#foto_"+fotoID;
	$.get(ajaxBase + "deleteFoto.php", { myFotoID: fotoID },
   function(data){
		if(data == "<div class='message success'><p>Das Bild wurde erfolgreich entfernt.</p></div>") {
			$(objFoto).remove();
			$('#msgcontainer').prepend(data);
		} else {
			$('#msgcontainer').prepend(data);
		}
		scrollToTop();			
   });
}

function deleteObject(objectID) {
	var objObject = "#object_"+objectID;
	var check;
	check = confirm(unescape("Wollen Sie dieses Objekt und die damit assoziierten Fotos wirklich l%F6schen%3F"));
	if (check == true) {
		$.get(ajaxBase + "deleteObject.php", { myObjectID: objectID },
	    function(data){
			if(data == "<div class='message success'><p>Das Objekt wurde erfolgreich entfernt.</p></div>") {
				$(objObject).remove();
				$('#msgcontainer').prepend(data);
			} else {
				$('#msgcontainer').prepend(data);
			}
			scrollToTop();			
	    });
   }
}

function displayLogos(intCatID) {
	$('#activeLogos').fadeOut(1);
	$('#activeLogos').attr('id', 'notactiveLogos');
	
	var myDiv = '#logorow-'+intCatID;
	$.each($(myDiv).children(), function () {
		if($(this).hasClass('stage-itemLine')) {
			$(this).attr('id', 'activeLogos');
			$(this).fadeIn(2000);
		}
	});
}

function scrollToTop() {
	
	$("html, body").animate({scrollTop:0}, "slow");
	
}

function styleMessages() {
	// Messages
	//*******************************************************************************************
	$('.message').hide().append('<span class="close" title="Schliessen"></span>').fadeIn('slow');
	$('.message .close').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	);
		
	$('.message .close').click(function() {
		$(this).parent().fadeOut('slow', function() { $(this).remove(); });
	});
}

//JQUERY Image List
$(document).ready(function(){

	styleMessages();

	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.boxgrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});

	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
	});
	
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.bannergrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});

	//Vorhang auf
	//$('.bannergrid.caption.cover').animate({top:'130px'},{queue:false,duration:500});
	//Caption Sliding (Partially Hidden to Visible)
	$('.bannergrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'174px'},{queue:false,duration:160});
	});	
});
