jQuery(function(){		
	/* SUCHE */
	default_val('s','Suche');
	default_val('consumption-home','kWh');	
	default_val('zip-code-home','PLZ');	

	/* NEWSTICKER */
	if(	jQuery('marquee')){
		jQuery('marquee').marquee().mouseover(function () {
	            jQuery(this).trigger('stop');
	        }).mouseout(function () {
	            jQuery(this).trigger('start');
	        }).mousemove(function (event) {
	            if (jQuery(this).data('drag') == true) {
	                this.scrollLeft = jQuery(this).data('scrollX') + (jQuery(this).data('x') - event.clientX);
	            }
	        }).mousedown(function (event) {
	            jQuery(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	        }).mouseup(function () {
	            jQuery(this).data('drag', false);
	        });
	}
	
	// Slider
	jQuery('a.slider').smartslider({
		scrollTo: true,
		unbind: true
	});
	
	
	// SMART METERING UMFRAGE
	checkHideShow( '#tarifwechsel-uninteressant_wrapper' ,'#tarifwechsel_wrapper input', '#tarifwechsel_fur-mich-ist-der-tarif-uninteressant-weil');
	checkHideShow( '#verbrauchsverhaltentext_wrapper' ,'#verbrauchsverhalten_wrapper input', '#verbrauchsverhalten_ja');
	checkHideShow( '#erwartungentext_ja_wrapper' ,'#erwartungen_wrapper input', '#erwartungen_ja');
	checkHideShow( '#erwartungentext_nein_wrapper' ,'#erwartungen_wrapper input', '#erwartungen_wrapper :eq(3)');
	checkHideShow( '#betreuung-ja_wrapper' ,'#betreuung_wrapper input', '#betreuung_wrapper :eq(0)');
	checkHideShow( '#betreuung-nein_wrapper' ,'#betreuung_wrapper input', '#betreuung_wrapper :eq(3)');
});



function checkHideShow( hide, bindOn, toCheck) {
	var $hide = jQuery(hide);
	var $bindOn = jQuery(bindOn);
	var $toCheck = jQuery(toCheck);
		
	if ( !$toCheck.attr('checked') )
		$hide.hide();

	$bindOn.change(function(){
		if ( $toCheck.attr('checked') )
			$hide.show();
		else
			$hide.hide();
	});
}



function createSlider(SliderElement){
   var Ar = jQuery(SliderElement);
   //var aSize =jQuery(SliderElement).size();
   Ar.each(function(i){
       var aAttributes = jQuery(this).attr("href");
       jQuery(aAttributes).hide();
       jQuery(this).click(function(){
           jQuery(aAttributes).toggle("slow");

           if(jQuery(this).hasClass("slideactive"))
               jQuery(this).removeClass("slideactive");
           else
               jQuery(this).addClass("slideactive");
       });

   });
}

function default_val(id, value) {
	jQuery('#'+id).click(function(){
		if (jQuery('#'+id).val() == value) jQuery('#'+id).val('');
	});
	jQuery('#'+id).blur(function(){
		if (jQuery('#'+id).val() == '') jQuery('#'+id).val(value);
	});
	if (jQuery('#'+id).val() == '') jQuery('#'+id).val(value);
}

function toggle(tarif)
{
	jQuery('#box_' + tarif).toggle();
	jQuery('#box_small_' + tarif).toggle();
}

(function($){
	$.fn.smartslider = function(options) {
	
		var defaults = {
			closedClass : 'closed',
			openClass : 'opened',
			scrollTo : false,
			speed : 'fast',
			trigger : 'click',
			targetAttribute : 'href',
			unbind : false
		};

		var options = $.extend(defaults, options);

		return this.each(function() {
			obj = $(this);
			
			if (true === options.unbind)
				obj.unbind(options.trigger);
			
			// Get target Element
			var target = jQuery(obj.attr(options.targetAttribute));

			// Hide target Element
			if ( !obj.hasClass(options.openClass) && !target.hasClass(options.openClass) )
			{
				target.hide();
			 	obj.addClass(options.closedClass);
			 	target.addClass(options.closedClass);
			}

			// Bind toggle
			jQuery(this).bind(options.trigger,function(){
				
				// Toggle
				target.toggle(options.speed);

				// Add CSS Classes for styling
				if (obj.hasClass(options.openClass))
				{
					obj.removeClass(options.openClass);
					obj.addClass(options.closedClass);
					
					target.removeClass(options.openClass);
					target.addClass(options.closedClass);
				}
				// Add CSS Classes for styling
				else
				{
					obj.removeClass(options.closedClass);
					obj.addClass(options.openClass);
					
					target.removeClass(options.closedClass);
					target.addClass(options.openClass);
					
					if (true == options.scrollTo)
					{
						offSet = parseInt(target.offset().top);
						jQuery('html').animate({
							scrollTop: offSet
						}, 'slow');
					}
				}
				return false;
			});
			
		});
	};
})(jQuery);
