
/*
* www.peter-kaiser.de
* Start: 18.02.2009
* Letzte Aenderung: 20.03.2010 by Martin Teufel {oop-solutions}
*/

<!--//---------------------------------+
//  Developed by Hannes Kober, Martin Teufel
//  This notice MUST stay intact for legal use
// --------------------------------->

/* News-Slide */
var button_img = null;
var config = { 
  sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
  interval: 100, // number = milliseconds for onMouseOver polling interval    
  over: makeTall, // function = onMouseOver callback (REQUIRED)    
  timeout: 100, // number = milliseconds delay before onMouseOut    
  out: makeShort // function = onMouseOut callback (REQUIRED)    
};

function makeTall(){
  $(this).animate({"height":92},500).addClass("redstripe");
  $(this).children('.newstext').children ('h2').css('color', '#333333');
}
function makeShort(){
  $(this).animate({"height":55},500).removeClass("redstripe");
  $(this).children('.newstext').children ('h2').css('color', '#cacaca');
}

$(document).ready(function()
{
	 /*
  if($('a#google_maps').length > 0){
	  
	$('a#google_maps').click(function(e){
		var width = ($(window).width() * 90 / 100); 
		var height = ($(window).height() * 75 / 100);
		e.preventDefault();
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: '',
			'width'			: width,
			'height'		: height,
			'href'			: this.href,
			'type'			: 'iframe',
			'scrolling'		: 'no',
			'overlayColor'  : '#d6d6d6',
			'overlayOpacity': 0.8
			//'onComplete'	:	function() {}
		});

	});
  } */

  $(window).resize(function() {
    $('#map_container').css({height:$(window).height()-210});
  });

  if($('form#search_dealer_locator').length > 0){
    /*
    $('#send_dealer_locator').mousedown(function() {
      button_img = $(this).css('background');
      $(this).css('background', 'transparent url(/files/layout/img/btn.go.over.png) no-repeat 0 0');
    });
    $('#send_dealer_locator').mouseup(function() {
      $(this).css('background', button_img);
    });

    $('input#customerLocationInput').focus(function(){
      if($(this).val() == address_error){
        $(this).val('');
        $(this).removeClass('error');
      }
    });*/

    $('form#search_dealer_locator').submit(function(e){
      e.preventDefault();
      var width = ($(window).width() * 95 / 100);
      var height = ($(window).height() *90 / 100);
      var address  = $('input#customerLocationInput').val();
      var country = ($('ul#countrySelect > li').hasClass('current')) ? $('ul#countrySelect > li.current a').attr('href') : $('ul#countrySelect > li:first-child a').attr('href')
      country = sub_string(country, 1, country.length);
      var url = $(this).attr('action');

      if(address == ''){
        $('input#customerLocationInput').addClass('error');
        $('input#customerLocationInput').val(address_error);
        return false;
      }
      
      $.fancybox({
        'padding'		: 0,
        'autoScale'		: false,
        'transitionIn'	: 'none',
        'transitionOut'	: 'none',
        'title'			: '',
        'width'			: width,
        'height'		: height,
        'href'			: url+'?setHaendler=1&address='+address+'&country='+country,
        'type'			: 'iframe',
        'scrolling'		: 'no',
        'overlayColor'  : '#d6d6d6',
        'overlayOpacity': 0.8,
        'onComplete'	:	function() {

        }
      });

    });
  }  

  if($("a.group").length > 1){
    $("a.group").fancybox({
				'titlePosition'  : 'inside',
				'overlayColor'   : '#000',
				'overlayOpacity' : 0.5
			});
  }


  if(false && $(".news").length > 0){
    $(".news").css('cursor', 'pointer');
    $(".news").hoverIntent( config );
    $(".news").click(function(e){
      location.href = $('.newstext h2 a', this).attr('href');
    });
  }
  if($('.teaser_item').length > 0){
    $('.teaser_item .active').css('opacity', 0);
    $('.teaser_item')
      .mouseover(function(){
          $(this).children('.active').stop().animate({opacity: 1}, 500).parent().addClass('active').children('.teaser_border').stop().show().animate({height: 4}, 300);
      })
      .mouseout(function(){
        $(this).children('.active').stop().animate({opacity: 0}, 500).parent().removeClass('active').children('.teaser_border').stop().hide().animate({height: 0}, 300);
      })
  }

  
  /** STORES **/
 if($('#hdls_container #countrySelect').length > 0){
  $('.hdls_left > img').css({opacity: 0});
  $('.hdls_left > img.active').css({opacity: 1});


	$('#countrySelect > li').click(function(e){
 		  e.preventDefault();
 		  if($('#countrySelect').height() == 75){
 	       $("#countrySelect").animate({height:25}, 500, function(){
           $(this).removeClass('open');
         });
 		  }
 		  else{
 	       $("#countrySelect").animate({height:75}, 500).addClass('open');
 		  }
 		});

 		$('#countrySelect a.country').click(function(e){
 		  e.preventDefault();

 	     if($(this).parent().is(".current") == false){

        var node = $(this).parent();
        var classTmp = $(this).attr('href').substr(1, $(this).attr('href').length);
        var className = classTmp.substr(1, classTmp.length).toLowerCase();
				var current   = $('.hdls_left img.active');
				var next	    = $('img#map_'+classTmp);

				next
				  .css({opacity: 0.0})
  	  		.addClass('active')
  	  		.animate({opacity: 1.0}, 1500);

  			current
  	  		.animate({opacity: 0.0}, 1500)
  	  		.removeClass('active');

        $("#countrySelect")
          .animate({height:25}, 500, "", function(){
            $("#countrySelect > li.current").removeClass('current');
            node.addClass('current');
            
            if($("#countrySelect li").eq(0).hasClass('current')){
              $("#countrySelect li").eq(0).removeClass('spacer');
              $("#countrySelect li").eq(1).addClass('spacer');
            }
            else {
              $("#countrySelect li").eq(0).addClass('spacer');
              $("#countrySelect li").eq(1).removeClass('spacer');
            }
          })
          

          //loadCountry(className);
        }
        else{
          $("#countrySelect").animate({height:75}, 500);
        }
      });
      if($("#countrySelect li:first-child").hasClass('current'))
        $("#countrySelect li:first-child").next().addClass('spacer');
 }
});


function sub_string(str, from, to){
  var newString = str.substring(from, to);

  return newString;
}

function is_int(input){
  return !isNaN(input)&&parseInt(input)==input;
}
      
function get_url_param(url, name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );

	if ( results == null )
		return "";
	else
		return results[1];
}
      
