$j = jQuery.noConflict();

$j(document).ready(function() {
	/**
	* myquiz check selected answer
	*/
	$j('form#myquiz_form').submit(function() {
		if($j('input:radio:checked').length < 1) {
			alert("Bitte wählen Sie eine Antwort aus.");
			return false;
		}
		return true;
	});

	/**
	* Bookmarklet
	*/
	$j('#bookmark_page').click(function() {

		var title = document.title
		var url = window.location;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) {
			window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
			return true;
		}
		return false;
	});
	//////////////////////////////////////////////////////
	/**
	* Seite drucken
	*/
	$j('#print_page').click(function() {
		window.print();
		return false;
	});
	//////////////////////////////////////////////////////
	/**
	* Pulldown Menu
	*
	$j('ul.jd_menu').jdMenu({
		hideDelay: 500,
		disableLinks: false
	});
	*/

	$j('a[rel*=lightbox]').facebox({
		loadingImage: 'fileadmin/templates/scripts/facebox/loading.gif',
		closeImage: 'fileadmin/templates/scripts/facebox/closelabel.gif',
		opacity: 0.5
	})
	//////////////////////////////////////////////////////
	/**
	* Dealer Search
	*/
	var dealerVal = $j('#dealer_search').val();
	$j('#dealer_search').focus(function() {
		$j(this).val('');
	})
	$j('#dealer_search').blur(function() {
		if($j(this).val() == '' ) {
			$j(this).val(dealerVal);
		}

	})
	
	
	$j('#mapguide_link').click(function() {
		
		jQuery.facebox($j('#mapandguide_frame').clone().show());

		return false;	
	})
	
	/**
	* Indexed Search
	*/
	var searchVal = $j('#indexed_search').val();
	$j('#indexed_search').focus(function() {

		$j(this).val('');


	})
	$j('#indexed_search').blur(function() {
		if($j(this).val() == '' ) {
			$j(this).val(searchVal);
		}

	})

	/**
	* odd Mailform
	*/
	$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');

	/**
	* Direct Step Form
	*/
	$j('#directstep > form').submit(function(){
		var page = $j('#directstep > form > select').val();
		window.location = "?id="+page;
		return false;
	});
	$j('#directstep > form > select').change(function(){
		var page = $j('#directstep > form > select').val();
		window.location = "?id="+page;
		return false;
	});

	/**
	* Teaser image switch
	*/
	var activImage = 2;
	var timer;

	$j('div.teaser-switch > ul').each(function() {
		$j('div.teaser-switch > ul > li').each(function(i,item) {


			var titel = $j(this).children('a').attr('title');

			var li = $j('<li><a href=""><span>'+titel+'</span></a></li>');

			if(i == 0) {
				$j(this).show();
				li.addClass('activ');
			}

			var that = $j(this);
			li.children('a').click(function() {
				$j('div.teaser-switch > ul > li').hide();
				$j(that).fadeIn('slow');
				$j('div.switch-menu > ul > li').removeClass('activ');
				$j(this).parent().addClass('activ');

				window.clearTimeout(timer);

				return false;
			});
			$j('div.switch-menu > ul').append(li);
		});
	})


	function teaserTimeSwitcher() {

		var item = $j('div.teaser-switch > ul > li:nth-child('+activImage+')');

		if(item.length != 0) {
			$j('div.teaser-switch > ul > li').hide();
			$j(item).fadeIn(2000);
			$j('div.switch-menu > ul > li').removeClass('activ');
			$j('div.switch-menu > ul > li:nth-child('+activImage+')').addClass('activ');


			if(activImage == $j('div.teaser-switch > ul > li').length) {
				activImage = 1;
			} else {
				activImage+=1;
			}


		}

		//timer = setTimeout(teaserTimeSwitcher, 6000);
	}
	/**
	 * Wird für KW27 nicht gewechselt
	 * @author Fstrauss
	 * @since 01.07.2009
	 */
	//timer = setTimeout(teaserTimeSwitcher, 6000);






	/**
	* bullet List im #CE Bereich odd/even
	*/
	$j('#CE').find('ul > li:odd').addClass('odd');
	$j('#CE').find('ul > li:even').addClass('even');

	$j('#CE').find('ol > li:odd').addClass('odd');
	$j('#CE').find('ol > li:even').addClass('even');

	$j('#CE').find('table > tbody > tr:even').addClass('tr-odd');
	$j('#CE').find('table > tbody > tr:even').addClass('tr-even');


	$j('div.product-recommendation-container').productRecommendation();

	/**
	 * Temporäre Lightbox
	 */
	var url ="http://101539.webhosting39.1blu.de/Ferrero/index.php?option=com_hz&view=kino&hdp=HDP.1004";
	var item  = jQuery('a[href='+ url +']');

	item.click(function() {
		jQuery.facebox('<iframe src="'+url+'" style="border:0;width:1000px;height:450px;" ></iframe>')

		return false;
	})
	var imageList = $j("<table>");
	imageList.attr("id","copyrightTable");
	imageList.append($j("<tr>")
	    .append($j("<td>").html("<strong>Bildnachweis</strong>"))
	);

	var row = "";
	var drawCopyrights = false;
	$j("img[copyright]").each(function(i,item) {
		if($j(item).attr("copyright").length > 5) {
			drawCopyrights = true;
	    	row = $j("<td>");
	    	row.html($j(item).attr("copyright"));
	    	imageList.append($j("<tr>").html(row));
		}
	});

	if(drawCopyrights) {
		$j("#copyrightTable").empty();
		var copyrightContent = $j("<div>");
		copyrightContent.attr("id","copyrightContent");
		copyrightContent.html(imageList);
		$j("#content").append(copyrightContent);
	}
});

