﻿(function(){ // Import GET Vars
   document.$_GET = [];
   var urlHalves = String(document.location).split('?');
   if(urlHalves[1]){
      var urlVars = urlHalves[1].split('&');
      for(var i=0; i<=(urlVars.length); i++){
         if(urlVars[i]){
            var urlVarPair = urlVars[i].split('=');
            document.$_GET[urlVarPair[0]] = urlVarPair[1];
         }
      }
   }
})();

function get_stage_dimensions () {
	midx = parseInt($('#stage').css('width'))/2; verbose("midx = " + midx);
	midy = parseInt($('#stage').css('height'))/2; verbose("midy = " + midy);
}

function get_images () {
  	var array = [];
	$.get(csvfile, function(data) { 
		array = data.split("\n"); // Exploding file containing image list
	
		ctr=0;		
		$.each(array, function() { 
    		array2 = this.split(",");    		
    		$('#stage').append($('<div class="draggable" id="drag'+ctr+'" style="border: none; background: transparent;"><a href="JavaScript: void(0);"><img class="stage-image" id="img'+ctr+'" /></a></div>'));// Appending div with image to stage
			//alert (array2[0]);
			$('#img'+ctr).attr('src',bilder_speicherort+array2[0]);
		  	$('#img'+ctr).load(function() {
  			   	rotate_image(this);
  			});   
			if (bilder_verschieben == true) { $('#drag'+ctr).draggable({ stack: '.draggable'}); } // Making it draggable if enabled in settings
 			$('#drag'+ctr).css('width',parseInt($('#img'+ctr).css('width'))); // Setting div width to image width
 			$('#drag'+ctr).css('width',thumbnail_breite+'px');
 			$('#drag'+ctr).css('height',thumbnail_hoehe+'px');					  
			if (bilder_platzieren == false) place_image('#drag'+ctr,'random');
			add_effects('#drag'+ctr,'#img'+ctr,array2[0]);
							
				 
						//  if (this != "" && bilder_platzieren == true) {
						// 				    $('#img'+ctr).css('position','absolute');
						// 				  	$('#img'+ctr).css('left',this);
						// 				  	}
						// 			  if (this != "" && bilder_platzieren == true) {
						// 					$('#img'+ctr).css('position','absolute');
						// 				  	$('#img'+ctr).css('top',this);
						// 				  	}
				
		
		ctr++; // Going to next image
	});	
	});
}

function rotate_image (image) {
 	var maxangle = Math.floor(Math.random() * (maximale_bilddrehung - (-maximale_bilddrehung) + 1)) + (-maximale_bilddrehung); // Random angle between 0 and maxrot variable from settings
	$(image).rotate(maxangle);
}

function place_image (image, type) {
	switch (type) {
	case "random":

		var wid = thumbnail_breite;
		var hei = thumbnail_hoehe;

		var xpos = Math.round(Math.random() * (xmax-(0-xmax)));
		xpos = xpos*(-1); verbose("xpos = "+xpos);
		if ((ctr%2) == 0) xpos = xpos*(-1); verbose("xpos = "+xpos);
		xpos = (midx - (wid/2)) + xpos; verbose("xposNEU = "+xpos);
		var ypos = Math.round(Math.random() * (ymax-0));
		if ((ctr%2) != 0) ypos = ypos*(-1); verbose("ypos = "+ypos);
		ypos = (midy - (hei/2)) + ypos; verbose("yposNEU = "+ypos);
		$(image).css('position','absolute');
		$(image).css('top',ypos+ybias);
		$(image).css('left',xpos+xbias);
		break;
	}
	$(image).css('z-index',100);		
}

function add_effects (image,html_id,content_id) {
	$(image).css('opacity',transparenz);
	
	$(image).live('mouseout', function() {
		//$('#teaser').css('display','block');
		//$('#teaser').css('display','none').fadeIn(50);
		verbose("scalemax = "+scalemax);
		$(html_id).css('width',parseInt($(html_id).css('width'))-scalemax);
		$(html_id).css('height',parseInt($(html_id).css('height'))-scalemax);
		$(this).css('opacity',transparenz);
		//$(this).css('z-index','100');
	});
	
	$(image).live('mouseenter', function() {
		//$('#teaser').css('display','block');
		//$('#teaser').css('display','none').fadeIn(50);
		//alert (parseInt($(this).css('width'))+scalemax);
		
		$(html_id).css('width',parseInt($(html_id).css('width'))+scalemax);
		$(html_id).css('height',parseInt($(html_id).css('height'))+scalemax);
		$(this).css('opacity','1');
 		//$(this).css('z-index','200');
	});
	
	$(image).live('click', function(event) {
		$('.draggable').css('display','none');
		$(image).css('display','block');
		$(image).css('top','100px');
		$(image).css('left','20px');		
		
		if (content_fenster_schatten == true) $('#pb-content').removeShadow();
		$('#pb-content').css('width',content_fenster_breite);
		$('#pb-content').css('height',content_fenster_hoehe);
		
		if (content_fenster_schatten == true) {
			var shadow = $('#pb-content').dropShadow({left: 2, top: 2, opacity: 0.8, blur: 2});
			shadow.css('width',content_fenster_breite);
			shadow.css('height',content_fenster_hoehe);
			shadow.css('top',event.pageY-165);
			shadow.css('left',event.pageX);
			}
		
		if (content_fenster_mauspos == false) {
			if (titel_ausblenden == true) $('#pinboard-title').css('display','none');
			$('#pb-content').css('top',content_fenster_y);
			$('#pb-content').css('left',content_fenster_x);
			}

		if (content_fenster_mauspos == true) {
			$('#pb-content').css('top',event.pageY-165);
			$('#pb-content').css('left',event.pageX+'px');
		
			var contentRight = parseInt($('#pb-content').css('width')) + event.pageX; 
			var contentBottom = parseInt($('#pb-content').css('height')) + event.pageY - 165;
		
			if (contentRight > parseInt($('#stage').css('width'))) {
				$('#pb-content').css('left',0.97*(parseInt($('#stage').css('width'))-parseInt(content_fenster_breite))+"px");
				if (content_fenster_schatten == true) shadow.css('left',0.97*(parseInt($('#stage').css('width'))-parseInt(content_fenster_breite))+"px");
				}

			if (contentBottom > parseInt($('#stage').css('height'))) {
				$('#pb-content').css('top',0.93*(parseInt($('#stage').css('height'))-parseInt(content_fenster_hoehe))+"px");
				if (content_fenster_schatten == true) shadow.css('top',0.93*(parseInt($('#stage').css('height'))-parseInt(content_fenster_hoehe))+"px");
				}
			}
		
		if (content_fenster_schatten == true) shadow.redrawShadow({left: 2, top: 2, opacity: 0.8, blur: 2});
		$('#pb-content').css('z-index','500');
		//$('#pb-content').css('display','block');
		loadImg(content_id);

	
		//$('#content').css('display','none').fadeIn(300);contentid = (parseInt(event.target.id.substr(3)));$('#content').html();
	});
	
	$('#close').live('click', function() {
			if (content_fenster_schatten == true) $('#pb-content').removeShadow();
			$('.draggable').css('display','block');
			
			$('#pb-content').css('display','block').fadeOut(200);
			$('#pb-content').html('');
	});
}

function loadImg(image) {
	
	//$('#content').css('display','none').fadeIn(500).load('content/'+image.substring(0,image.length-4)+'.html'); // Loading file IMAGE-FILENAME.html to content-div 
	//$('#pb-content').load(content_url+'/'+image.substring(0,image.length-4)+'.html', function () { // Loading file IMAGE-FILENAME.html to content-div 
	if (content_aus_parent == true) loadanchor=document.location + ' #' + image.substring(0,image.length-4);
	if (content_aus_parent == false) loadanchor=content_url+'/'+image.substring(0,image.length-4)+'.html'

	$('#pb-content').load(loadanchor, function () { // Loading to content-div 
		$.get(csvfile, function(data) { 
			array = data.split("\n"); // Exploding file containing image list
			ctr=1;
			$.each(array, function() { 
				array2 = this.split(",");
				if (array2[0] == image) {
					imagecode = '<img src="'+bilder_speicherort+array2[0]+'" />';
					$('#pb-content #bild').html(imagecode);
	
					if (array2[3] && array2[3] != "") {
						array2[3] = escape(array2[3]);
						embedcode = ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" height="20" width="200"><param name="movie" value="http://fritz.de/frz/grafik/flash/mp3_player_mod4.swf" /><param name="quality" value="high" /><param name="flashvars" value="file='+array2[3]+'&amp;backcolor=0xffff00&amp;frontcolor=0xcc0000&amp;lightcolor=0x000000" /><embed src="http://fritz.de/frz/grafik/flash/mp3_player_mod4.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="file='+array2[3]+'&amp;backcolor=0xffff00&amp;frontcolor=0xcc0000&amp;lightcolor=0x000000" height="20" width="200"></object>');
						$('#pb-content #media').html(embedcode);   		
					}
				}    		
			});
		});
	
	
	$('#pb-content').append('<div id="close-button"><a href="JavaScript:void(0);" id="close">X SCHLIESSEN</a></div>');
	});

    $('#pb-content').ready(function () { $('#pb-content').css('display','block'); });
}

function verbose(msg) {
	var message = $('#debug').html() + "<br />" + msg;
	if (debuginfo != false) $('#debug').html(message);
}

