/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 2.1
 * 
 * Thanks to 
 * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 * Tom Leonard for some improvements
 * 
 */
jQuery.fn.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* 
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if ($(this).attr("nodeName")=="#document") {
	  	//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if ($(this).attr("src")!="undefined") {
	  	
	  	var strHref = $(this).attr("src")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else if ($(this).attr("href")!="undefined") {
	  	
	  	var strHref = $(this).attr("href")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else {
	  	return null;
	  }
	  	
	  
	  if (qString==null) return null;
	  
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}
			
	  }
	  
	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});















/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("area, a.button, a.schatzicon_gross, input.button").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("area, a.button, a.schatzicon_gross, input.button").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};




$(document).ready(function() {
	
tooltip();	






 

var pathname = window.location.pathname;

var word = pathname.split("/");
for(x = 0; x < word.length; x++){
    if(word[x] == 'standort'){
	$('#content .mod_catalogfilter div.filter_field_marken').show();	
  
  
    }
}


$('.startseite .bildelement').delay(2000).fadeOut("slow");
$('.startseite .bildelement').hover(function() {
				$(this).fadeOut("slow");
});




$('#ctrl_239,#ctrl_240,#ctrl_241,#ctrl_242,#ctrl_243,#ctrl_244,#ctrl_245,#ctrl_246').hide();
$('label[for=ctrl_239], label[for=ctrl_240], label[for=ctrl_241], label[for=ctrl_242], label[for=ctrl_243], label[for=ctrl_244], label[for=ctrl_245], label[for=ctrl_246]').hide();


$('#ctrl_215').change(function() {
    
	if ($("#ctrl_215").val() == "andere") { 
	
	$('#ctrl_239,#ctrl_240,#ctrl_241,#ctrl_242,#ctrl_243,#ctrl_244,#ctrl_245,#ctrl_246').show();
	$('label[for=ctrl_239], label[for=ctrl_240], label[for=ctrl_241], label[for=ctrl_242], label[for=ctrl_243], label[for=ctrl_244], label[for=ctrl_245], label[for=ctrl_246]').show();
	
	
	 }
	 
	 else {
		 $('#ctrl_239,#ctrl_240,#ctrl_241,#ctrl_242,#ctrl_243,#ctrl_244,#ctrl_245,#ctrl_246').hide();
		 $('label[for=ctrl_239], label[for=ctrl_240], label[for=ctrl_241], label[for=ctrl_242], label[for=ctrl_243], label[for=ctrl_244], label[for=ctrl_245], label[for=ctrl_246]').hide();
	 }
	
});




$('article.newsitem a.thumb ').hover(function() {
					$(this).next('.addpic').stop(true, true).fadeIn("fast");
				}, function() {
					$(this).next('.addpic').fadeOut("fast");
				});
				

$("a[href^='http://'], area[href^='http://'], a.popup").not(".backlink").attr("target", "_blank");

// 25 89 275


$('#ctrl_25, #ctrl_89, #ctrl_275').DatePicker({
	format:'d.m.Y',
	date: $('#ctrl_25, #ctrl_89, #ctrl_275').val(),
	current: $('#ctrl_25, #ctrl_89, #ctrl_275').val(),
	starts: 1,
	position: 'r',
	locale: {
					days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
					daysShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
					daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
					months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
					monthsShort: ["Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
					weekMin: 'wo'
				},
	onBeforeShow: function(){
		$('#ctrl_25, #ctrl_89, #ctrl_275').DatePickerSetDate($('#ctrl_25, #ctrl_89, #ctrl_275').val(), true);
	},
	onChange: function(formated, dates){
		$('#ctrl_25, #ctrl_89, #ctrl_275').val(formated);
		$('#ctrl_25, #ctrl_89, #ctrl_275').DatePickerHide();
		
	}
});



/* Addtabs fuer Reiter-Inhaltselemente */
if ($('.tabs').is('.addtabs')) { 


$('<ul class="tabnav"></ul>').prependTo('.addtabs');
$('.details.tabcontent').each(function() {
	$('#content .tabnav').append('<li><a href="#'+$(this).attr('id')+'">'+$(this).attr('title')+'</a></li>');
  
  });


}





	
	/* Chat */	
$('<a class="closechat">Chat schliessen</a>').insertBefore('#chatbutton, #chatframe').hide();
$('.closechat').click(function() { 
	$.cookie("chat", null);
	location.reload();		
			
});
	
	
			
if(!$.cookie("chat")) {
			
$('#chatbutton').removeAttr("href").click(function() {
		$('#chat').prepend(' <iframe id="chatframe" src="http://www.ostermaier.de/webim/client.php" width="272" height="500" scrolling="no" ></iframe>');
		$.cookie("chat");
		$.cookie("chat", "an", {expires: 1});
		$('#chatbutton').hide(0,function() { $('#chatframe, #chat').show(); });
		$('.closechat').show();
		
		
		
		}); 
}

else { 
$('#chatbutton').hide();
$('#chat').prepend(' <iframe id="chatframe" src="http://www.ostermaier.de/webim/client.php" width="272" height="500" scrolling="no" ></iframe>'); 
$('.closechat').show();

}
/* /Chat */
	
/* Stage Animationen, Funktion ganz unten */	
animateOnHover('.appendgallery', '.appendgallery h3', 'h1 a');	
animateOnHover('.ce_videobox', 'ul#marken, #breadcrumb', 'h1 a');
animateOnHover('iframe', 'ul#marken', 'h1 a');
/* animateOnHover('.flashcontainer', 'ul#marken', 'h1 a'); */
	
	



	
	
// Navi	
$('#nav li ul').hide();

$('#content .tabs').tabs({cookie: { expires: 30 }});
$('#content #fahrzeugdetail .tabs').tabs({ selected: 3 });
$('#sidebar .tabs').tabs();

$('#nav li').not('#nav li li').hover(function() {
											  $(this).addClass("hoverbaby");
											  $('.hoverbaby ul').stop(true, true).delay(380).slideDown(400);
											   }, function() {
											  $('.hoverbaby ul').stop(true, true).fadeOut(200);
											  $(this).removeClass("hoverbaby");
											  
											   });

$('.ce_gallery a img').parents('a').colorbox();

$("a.fullview").not("a[href^='http://']").colorbox();	
$(".video").colorbox({slideshow: true, slideshowSpeed: 500, slideshowAuto: true});
$("a[href$='.jpg'], a[rel^='lightbox']").colorbox();
$(".content a[href$='.pdf']").addClass("pdf");
$("a[href^='http://'], area[href^='http://']").not("a.backlink").attr("target", "_blank");

$("a.pdfgen").click(function() {
	$(this).append('<img src="http://ostermaier.de/autofamilie/tl_files/ostermaier/img/ajax-loader.gif" width="16" height="16" />');
	$(this).append('<p class="tooltip">Bitte warten</p>')
	
	
});

$('.slideshow').cycle({speed: 4000, delay: 5000, random:1});
$('ul#marken li').hover(function() { 
							 $(this).fadeTo(300, 0.7);
									 }, function() {
									$(this).fadeTo(300, 1.0);
							});
$('ul#nav ul').animate({opacity: 0.90}, 0);
$('a.button').animate({opacity: 0.50}, 0);
$('a img, h1#logo a, ul#lang a, a.button').not('header a img').hover(function() { 
									 
									 $(this).fadeTo(300, 0.8);
									 }, function() {
									$(this).fadeTo(300, 1.0);
									 	 
										 
									 });
									 

		
$('.appendgallery').appendTo('#mainheader').parent('#mainheader').addClass('keinemarken');
$('.hauptbild img').clone().appendTo('#mainheader').parent('#mainheader').addClass('keinemarken');

$('a.add *').hover(function() {
	
	$(a.add).hide(0);
})

$('#mainheader .appendgallery ul').after('<div id="pager">') 
.cycle({ 
    fx:     'fade', 
    speed:  '2000', 
    timeout: 7000, 
    pager:  '#pager'/* , 
	callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<a href="#"><img src="' + slide.src + '" width="50" height="50" /></a>'; 
    } */
});
$('#notfound').hide().siblings('h4').hide();


/* Sitemap */
$('footer .wrap').prepend("<div class=\"klapper\" id=\"auf\">Sitemap Ausklappen</div>");
$('footer .wrap').prepend("<div class=\"klapper\" id=\"zu\">Sitemap Zuklappen</div>");
$('#zu').hide();
$('.wrap').not('footer .wrap').css({"padding-bottom":"100px"});
$('footer').css({"height":"100px"});
$('footer .wrap').css({"height":"80px"});
$('footer nav').hide()
$('#auf').click(
			function() {
				$(this).hide();
				$('#zu').show(); 
				$('footer').animate({"height":"460px"},500, function() {$('footer nav').fadeIn("slow");});
				$('footer .wrap').animate({"height":"440px"},500);
				
			});
			
			
$('#zu').click(
			function() {
				$(this).hide();
				$('#auf').show();
				$('footer nav').hide(); 
				$('footer').animate({"height":"100px"},500);
				$('footer .wrap').animate({"height":"80px"},500);
				
			});
			

/* Telefon oder Email Formular */

$('#ctrl_36').hide(); $('#ctrl_36').prev().hide();
$('#opt_312_1').click(function() { $('#ctrl_36').show(); $('#ctrl_36').prev().show(); /* $('#ctrl_39').hide(); $('#ctrl_39').prev().hide(); */ });
$('#opt_312_0').click(function() { /* $('#ctrl_39').show(); $('#ctrl_39').prev().show(); */ $('#ctrl_36').hide(); $('#ctrl_36').prev().hide(); });


$('#ctrl_100').hide(); $('#ctrl_100').prev().hide();
$('#opt_313_1').click(function() { $('#ctrl_100').show(); $('#ctrl_100').prev().show(); /* $('#ctrl_39').hide(); $('#ctrl_39').prev().hide(); */ });
$('#opt_313_0').click(function() { /* $('#ctrl_39').show(); $('#ctrl_39').prev().show(); */ $('#ctrl_100').hide(); $('#ctrl_100').prev().hide(); });


$('#ctrl_359').hide(); $('#ctrl_359').prev().hide();
$('#opt_354_1').click(function() { $('#ctrl_359').show(); $('#ctrl_359').prev().show(); /* $('#ctrl_39').hide(); $('#ctrl_39').prev().hide(); */ });
$('#opt_354_0').click(function() { /* $('#ctrl_39').show(); $('#ctrl_39').prev().show(); */ $('#ctrl_359').hide(); $('#ctrl_359').prev().hide(); });



/* Callback */
$('#f22 #ctrl_328').hide(); $('#f22 #ctrl_328').prev().hide();
$('#f22 #ctrl_318').hide(); $('#f22 #ctrl_318').prev().hide();


/* Eigene Funktionen */
function animateOnHover($hoverElements, $fadeElements, $slideElements) { $($hoverElements).hover(function() {
				$($fadeElements).stop(true, true).fadeOut("slow");
				$($slideElements).stop(true, true).slideUp(1000);
	
				}, function() {
				$($fadeElements).stop(true, true).fadeIn("slow");
				$($slideElements).stop(true, true).slideDown(1000);
						
				
				});	
}


 });
