
function changeauswahl_suchen()
{
var such=document.getElementById("suchenbox").value;
document.getElementById("eventauswahl").selectedIndex=-1;
msg ('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+"Suche nach : "+such);
var htmll = $.ajax({
  url: "do_some_more.php",
  cache: false,
  data: "gewhlt="+such,
  async: false
 }).responseText;

// $("ul,'gallery ui-droppable'").css("border","3px solid red");
$("ul,'gallery ui-droppable'").html(htmll);
$('ul.gallery img').addClass('img_content').draggable({
		helper: 'clone'
	});
}

function changeauswahl()
{
var o = o=document.getElementById("eventauswahl").options;
var inhalt = document.getElementById("eventauswahl").selectedIndex;
msg ('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+"Lade : "+o[inhalt].text);
var htmll = $.ajax({
  url: "do_some.php",
  cache: false,
  data: "gewhlt="+o[inhalt].text,
  async: false
 }).responseText;

// $("ul,'gallery ui-droppable'").css("border","3px solid red");
$("ul,'gallery ui-droppable'").html(htmll);
$('ul.gallery img').addClass('img_content').draggable({
		helper: 'clone'
	});
}

function changeauswahl_start()
{
var o = o=document.getElementById("eventauswahl").options;
var inhalt = document.getElementById("eventauswahl").selectedIndex;

var htmll = $.ajax({
  url: "do_some.php",
  cache: false,
  data: "gewhlt="+o[inhalt].text,
  async: false
 }).responseText;

// $("ul,'gallery ui-droppable'").css("border","3px solid red");
$("ul,'gallery ui-droppable'").html(htmll);
$('ul.gallery img').addClass('img_content').draggable({
		helper: 'clone'
	});
}




function initz()   {$("#message").fadeOut("1");}	
function msg_out() {$("#message").fadeOut("slow");}
function msg_in()  {$("#message").fadeIn("slow");}

function msg(text)
{
// document.getElementById("message").innerHTML = "<center>" + text + "</center>";
// document.getElementById("message").style.visibility="visible";
$("#message").html("<center>" + text + "</center>");
// $("#message").css("visibility","visible");


var test = document.getElementById("message").style.border;
if (test =="")
{
$("#message").css("background-color","#0099FF");
$("#message").css("border","thin");
$("#message").css("border-color","#000000");
$("#message").css("border-style","solid");
$("#message").css("border-top","none");
}
msg_in();
setTimeout("msg_out()",500);    



}

function  anderes()
{
a = window.location= "http://www.fotokauf.at";
}
function disab()
{
document.getElementById("Bestellen").style.backgroundColor="#ff0000";
document.getElementById("Bestellen").style.color="#ffffff";
document.getElementById("Bestellen").value="Ausloggen";
document.getElementById("Bestellen").onclick= anderes;
// document.getElementById("Bestellen").disabled="disabled";
}


function bestellen()
{
var a = $("#trash .ui-droppable > *");
var ab = new Array();
for (var i = 0; i < a.length; i++) 
{
var neu = a[i].getAttribute("src");
var ganzneu = neu + "|";
ab.push(ganzneu);
}

if (ab > "")
{
msg('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fotos / Bilder bestellt...');
var htmll = $.ajax({
  url: "order.php",
  cache: false,
  data: "bilder="+ab+"&id="+globalid,
  async: false
 }).responseText;

disab();
alert (htmll);

}
else {msg('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keine Bilder zum bestellen in der Einkaufsbox...');
};
return false;
}


function updatepreis()
{
//document.getElementById("gesamtpreis").innerHTML = $("#trash .ui-droppable").children.length;
// $("#trash .ui-droppable").css("border","3px solid red");
// $("#trash .ui-droppable > *").css("border", "3px double red");
document.getElementById("bilderanzahl").innerHTML = $("#trash .ui-droppable > *").length;
document.getElementById("gesamtpreis").innerHTML ="<b>" + $("#trash .ui-droppable > *").length * globalpreis + "</b>";
document.getElementById("bilderpreis").innerHTML =  globalpreis;
}


function render()
{
var a = $("#trash .ui-droppable > *");
var ab = new Array();
for (var i = 0; i < a.length; i++) 
{
// var old = document.getElementById("bildernamen").innerHTML;
var neu = a[i].getAttribute("src");
var ganzneu = neu + "|";
ab.push(ganzneu);
}
if (ab =="") 
	{
	ab ="<center>Noch keine Bilder in der Einkaufsbox.</center>";
	};
//document.getElementById("bildernamen").innerHTML = ab;

}

$(window).bind('load', function() {
	// make images in the gallery draggable /// MAKES ERROR IN FUCKING IE BECAUSE OF LOAD SPEED
	//$('ul.gallery img').addClass('img_content').draggable({
	//	helper: 'clone'
	//});

	// make the trash box droppable, accepting images from the content section only
	$('#trash div').droppable({
		accept: '.img_content',
		activeClass: 'active',
		drop: function(ev, ui) {
			var $that = $(this);
			ui.draggable.parent().fadeOut('slow', function() {
				ui.draggable
					.hide()
					.appendTo($that)
					.fadeIn('slow')
					.animate({
						width: '72px',
						height: '54px'
					})
					.removeClass('img_content')
					.addClass('img_trash');
				$(this).remove();
				updatepreis();render();msg ('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+"f"+unescape("%FC")+"ge Foto hinzu...");
				
			});
		}
	});

	// make the shredder box droppable, accepting images from both content and trash sections
	$('#shred div').droppable({
		accept: '.img_content, .img_trash',
		activeClass: 'active',
		drop: function(ev, ui) {
			var $that = $(this);
			// images from the content
			if (ui.draggable.hasClass('img_content')) {
				ui.draggable.parent().fadeOut('slow', function() {
					ui.draggable
						.appendTo($that)
						.animate({
							width: '0',
							height: '0'
						}, 'slow', function(){
							$(this).remove();
						});
					$(this).remove();
				});
			}
			// images from the trash
			else if (ui.draggable.hasClass('img_trash')) {
				ui.draggable
					.appendTo($that)
					.animate({
						width: '0',
						height: '0'
					}, 'slow', function(){
						$(this).remove();
					});
			}
		}
	});

	// make the gallery droppable as well, accepting images from the trash only
	$('ul.gallery').droppable({
		accept: '.img_trash',
		activeClass: 'active',
		drop: function(ev, ui) {
			var $that = $(this);
			ui.draggable.fadeOut('slow', function() {
				var $item = createGalleryItem(this).appendTo($that);
				$(this)
					.removeClass('img_trash')
					.addClass('img_content')
					.css({ width: '144px', height: '108px' })
					.show();
				$item.fadeIn('slow');
				updatepreis();render();
				$("a.preview").css('background-image','url(theme/img/search_16.gif)'); 
				$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	
			});
		}
	});

	// handle the trash icon behavior
	$('a.tb_trash').livequery('click', function() {
		msg ('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+"f"+unescape("%FC")+"ge Foto hinzu...");
		var $this = $(this);
		var $img = $this.parent().siblings('img');
		var $item = $this.parents('li');

		$item.fadeOut('slow', function() {
			$img
				.hide()
				.appendTo('#trash div')
				.fadeIn('slow')
				.animate({
					width: '72px',
					height: '54px'
				})
				.removeClass('img_content')
				.addClass('img_trash');
			$(this).remove();
			updatepreis();render();
		});
		
		return false;
	});

	// handle the magnify button
//	$('a.tb_supersize').livequery('click', function() {
//		$('<img width="576" height="432">')
//			.attr('src', $(this).attr('href'))
//			.appendTo('#body_wrap')
//			.displayBox();
//		return false;
//	});






});

function createGalleryItem(img) {
	msg ('<img src="theme/img/load_blue.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+"entferne Foto...");
	var href = img.getAttribute('src').replace('_thumb', '_copy');

	var $item = $('<li><p>Retour</p><div><a href="#" title="Kaufen" class="tb_trash">Kaufen</a><a href="'+href+'" class="preview">asdf</a></div></li>').hide();
	$item.prepend($(img));
	
	return $item;
	
}

