/*
 * jQuery JavaScript Library v1.3.2
 * http://jquery.com/
 *
 * Copyright (c) 2009 John Resig
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
 * Revision: 6246 
 */

jQuery.noConflict();
//jQuery('#trailer').hide();
jQuery(document).ready(function($) {   
  
  $('.maximage').maxImage({
		maxFollows:'width',
		overflow: 'auto',
		position:'fixed',
		isBackground:true,
		verticalAlign: 'center',
		zIndex:(-10)
	});
	
	$(".logo_1").hover(
    function () {        	
	   $('.maximage').attr("src", 'fileadmin/template/images/bg1.jpg');
	   $('.green .hidden').addClass('visible');
	   $('.lila .hidden').removeClass('visible');
	   $('.yellow .hidden').removeClass('visible');
    }
  );
  
  $(".logo_2").hover(
    function () {        	
	   $('.maximage').attr("src", 'fileadmin/template/images/bg2.jpg');
	   $('.green .hidden').removeClass('visible');
	   $('.lila .hidden').addClass('visible');
	   $('.yellow .hidden').removeClass('visible');
    }
  );
  
  $(".logo_3").hover(
    function () {        	
	   $('.maximage').attr("src", 'fileadmin/template/images/bg3.jpg');
	   $('.green .hidden').removeClass('visible');
	   $('.lila .hidden').removeClass('visible');
	   $('.yellow .hidden').addClass('visible');
    }
  );
  
  /* Scrollable */
  $("div.scrollable").scrollable(
  {
    size: 5,
    hoverClass: 'hover',
    loop: true,   
    speed: 1000
  }).circular();
    
  $(".items img").click(function() {
  
  	// see if same thumb is being clicked
  	if ($(this).hasClass("active")) { return; }
  
  	// calclulate large image's URL based on the thumbnail URL (flickr specific)
  	var url = $(this).attr("src").replace("_t", "");
  
  	// get handle to element that wraps the image and make it semi-transparent
  	var wrap = $("#image_wrap").fadeIn("fast");
  
  	// the large image from www.flickr.com
  	var img = new Image();
  
  
  	// call this function after it's loaded
  	img.onload = function() {
  
  		// make wrapper fully visible
  		wrap.fadeTo("fast", 1);
  
  		// change the image
  		wrap.find("img").attr("src", url);
  
  	};
  
  	// begin loading the image from www.flickr.com
  	img.src = url;
  
  	// activate item
  	$(".items img").removeClass("active");
  	$(this).addClass("active");
  
  // when page loads simulate a "click" on the first image
  }).filter(":first").click();
  
  function getUrlVars()
  {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  }
  
  var textareaText = getUrlVars()['textarea'];
  var textareaText2 = getUrlVars()['textarea2'];
  
  if(textareaText)
  {
    textareaText = unescape(textareaText);
    $('textarea').val('Ich interessiere mich für das Fahrzeug "' + textareaText + '".');
  }
  
  if(textareaText2)
  {
    textareaText2 = unescape(textareaText2);
    $('textarea').val('Ich interessiere mich für die Immobilie "' + textareaText2 + '".');
  }

});
