$j = jQuery.noConflict();
$j(document).ready(function() {

	$j('#delivery_change').click(function() {
		if($j('#delivery_part').css('display') == "none") {
			$j('#delivery_part').fadeIn('slow');
		} else {
			$j('#delivery_part').fadeOut('slow');
		}

	})
	/**
	* Layout fix
	*/


	if($j('#innerwrapper').length != 1 ) {
		if($j('#leftSidebar').length != 0  && $j('#rightSidebar').length != 0) {
			$j('#content').css('width','524px').css('padding-right','5px')
		}
		if($j('#leftSidebar').length == 0  && $j('#rightSidebar').length != 0) {
			$j('#content').css('width','699px')
		}
		if($j('#leftSidebar').length == 0  && $j('#rightSidebar').length == 0) {
			$j('#content').css('width','927px')
		}
	}
	/**
	* Formular fix
	*/
	$j('form > fieldset > div:odd').addClass('odd')
	$j('form > fieldset > div > em').each(function(i,item) {
		$j(this).appendTo($j(this).parent().children('label'));
	})
	$j('form > fieldset > div input.submit').parent().addClass('buttons');

	/**
	 * Radio Spot
	 * @author Florian Strauss
	 * @since 02.06.09
	 *
	 * http://bugs.wgo-service.de/view.php?id=5950
	 */
	/*
	if($j.cookie('speaker') == "on" || !$j.cookie('speaker')) {
		$j("#sound").sound({
			swf: 'fileadmin/templates/sounds/Player.swf',
			file: 'fileadmin/templates/sounds/radiospot.mp3'
		});
		$j('#speaker').addClass('speaker-on');
		$j('#speaker').attr('src', 'fileadmin/templates/images/speaker_on.png');
	} else {
		$j("#sound").sound({
			swf: 'fileadmin/templates/sounds/Player.swf'
		});
		$j('#speaker').addClass('speaker-off');
		$j('#speaker').attr('src', 'fileadmin/templates/images/speaker_off.png');
	}


	
	
	$j('#speaker').click(function() {
	
		if($j(this).hasClass('speaker-on')) {
			$j.cookie('speaker', 'off');

			$j("#sound").stop();
			$j(this).removeClass('speaker-on');
			$j(this).addClass('speaker-off');
			$j(this).attr('src', 'fileadmin/templates/images/speaker_off.png')
		} else {
			$j.cookie('speaker', 'on');
			$j("#sound").load('fileadmin/templates/sounds/radiospot.mp3');
			$j("#sound").play();
			$j(this).removeClass('speaker-off');
			$j(this).addClass('speaker-on');
			$j(this).attr('src', 'fileadmin/templates/images/speaker_on.png')
		}
	})
	*/
	
	/**
	* Kategorie Overview Slider
	*/
	$j('div.sliderGallery').each(function () {
    	var ul = $j('ul', this);
    	var productWidth = ul.innerWidth() - $j(this).outerWidth();

    	var slider = $j('.slider', this).slider({
      		handle: '.handle',
      		min: 0,
      		max: productWidth,
      		slide: function (ev, ui) {
        		ul.css('left', '-' + ui.value + 'px');
      		},
      		stop: function (ev, ui) {
        		ul.animate({ 'left' : '-' + ui.value + 'px' }, 500, 'linear');
      		}
		});
	});

	/**
	* Carousel fï¿½r die Ecards
	*/
	$j("#ecards-carousel").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		visible: 3
	});

	/**
	* Shop
	*/

	function calculateTotalSum() {
		var totalSum = 0;
		$j('span.product_price').each(function() {
			var floatPrice = parseFloat($j(this).html().replace(/,/,'.'))
			totalSum+=floatPrice;
		});
		$j('#total_amount').html(""+totalSum.toFixed(2)+"".replace(/./,','));

	}
	if($j('#selected_product_id').length != 0) {

		var productID = $j('#selected_product_id').val();

		$j('#product_quantity_'+productID).val("1");
		var floatPrice = parseFloat($j('#product_price_original_'+productID).html().replace(/,/,'.'))
		var totalPrice = floatPrice*1;


		$j('#product_price_'+productID).html(""+totalPrice.toFixed(2)+"".replace(/./,','));
		calculateTotalSum();
	}

	if($j('input.product_quantity').length != 0) {
		$j('input.product_quantity').each(function() {
			var that = $j(this);

			$j(this).blur(function(){

				var id = that.attr('id').split("_")[2];
				console.log(id);
				var floatPrice = parseFloat($j('#product_price_original_'+id).html().replace(/,/,'.'));

				var totalPrice = floatPrice*parseInt(that.val());

				$j('#product_price_'+id).html(""+totalPrice.toFixed(2)+"".replace(/./,','));
				calculateTotalSum();
			});

		})
	}
	/**
	 * Wetter Widget
	 * @author Florian Strauss
	 * @since 02.06.2009
	 * Ticket: http://bugs.wgo-service.de/view.php?id=5957
	 */
	var activImage = 2;
	var timer;

	$j('#weather').find('li').hide();
	$j('#weather').find('li:first').show();


	function weatherSwitch() {

		var item = $j('#weather').find('li:nth-child('+activImage+')');

		if(item.length != 0) {
			$j('#weather').find('li').hide();
			$j(item).show();

			if(activImage == $j('#weather').find('li').length) {
				activImage = 1;
			} else {
				activImage+=1;
			}
		}

		timer = setTimeout(weatherSwitch, 6000);
	}
	timer = setTimeout(weatherSwitch, 6000);


	/**
	 * Qualitätsformular
	 * @ticket 6604
	 * @since 14.08.2009
	 * @author Fstrauss
	 */
	$j('label').each(function(i, item) {
		var height = $j(this).height() + 15;

		if(!$j(this).parent().find('textarea').length) {
			$j(this).parent().height(height)
		}
		
	});
	$j('input[type=text]').addClass('text');


});