$(document).ready(function() {

	$('div.marquee').marquee();

	$("div.manufac.narrow.gs").hover(function() {
		$(this).find("img.grey").hide();
		$(this).find("img.color").show();
		var color = $(this).find("div.ref").css('color');
		$(this).find("div.fancywrap").css('backgroundColor', color);
		$(this).css('borderColor', color);
	}, function() {
		$(this).find("img.grey").show();
		$(this).find("img.color").hide();
		$(this).find("div.fancywrap").css('backgroundColor', '#C1C1C1');
		$(this).css('borderColor', '#C1C1C1');
	});

	// Cyklování obrázků (náhrada flashe)
	$(".cycleimg").cycle({
		fx: 'fade',
		speed: 1000, 
		timeout: 5000, 
		cleartypeNoBg: true
	});

	// Lightbox pro obrázky a videa
	$("a.lightbox").fancybox({'type' : 'image'});
	$("a.textbox").fancybox({
			'width' : '80%',
			'height' : '60%',
			'autoScale' : true,
			'transitionIn' : 'fade',
			'transitionOut' : 'none',
			'type' : 'iframe'
			});
	$("a.fbox").fancybox({'scrolling' : 'no', 'type' : 'ajax'});

	// Různé maličkosti pro vyplňování formulářů
	$("input[name=odeslatDotaz]").click(function() {
		if ($("input[name=sender]").val() == 'vas@email.cz') $("input[name=sender]").val('');
		if ($("input[name=firma]").val() == 'Název firmy') $("input[name=firma]").val('');
		if ($("input[name=telefon]").val() == 'Telefonní číslo') $("input[name=telefon]").val('');
	});
	$("input[name=search]").focusin(function() {
		if ($(this).val() == 'Hledaný výraz') $(this).val('');
	});
	$("input[name=search]").focusout(function() {
		if ($(this).val() == '') $(this).val('Hledaný výraz');
	});
	$("input[name=sender]").focusin(function() {
		if ($(this).val() == 'vas@email.cz') $(this).val('');
	});
	$("input[name=sender]").focusout(function() {
		if ($(this).val() == '') $(this).val('vas@email.cz');
	});
	$("input[name=telefon]").focusin(function() {
		if ($(this).val() == 'Telefonní číslo') $(this).val('');
	});
	$("input[name=telefon]").focusout(function() {
		if ($(this).val() == '') $(this).val('Telefonní číslo');
	});
	$("input[name=firma]").focusin(function() {
		if ($(this).val() == 'Název firmy') $(this).val('');
	});
	$("input[name=firma]").focusout(function() {
		if ($(this).val() == '') $(this).val('Název firmy');
	});
	$('textarea').focusin(function() {
		$('textarea').animate({
			height: 200
		}, 'slow');
	});
	$('textarea').focusout(function() {
		$('textarea').animate({
			height: 50
		}, 'fast');
	});

	// Zobrazení a skrytí ajaxového loaderu
	$("#loading").ajaxStart(function(){
		$(this).show(0);
	});
	$("#loading").ajaxStop(function(){
		$(this).hide(0);
	});

	// Skrytí tabulky s parametry
	$("#skryt").click(function(){
		$("#parametry").hide('slow');
		$("#hidebtn").hide();
	});

	// Přidání ikonky pro odkazy vedoucí mimo tento web
	$('#content a').filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).after(' <img src="/images/external_link.png" alt="external" width="10" height="10" />');

});

function paramSelectjquery(id) {
	var url = "/inc/ajax.products-params.php";

	$.get(url, { ident: id, sid: Math.random() },
		function(data) {
			$("#parametry").html(data);
			$("#parametry").show('slow');
			$("#hidebtn").show('fast');
			});
	}

function reloadCompare(id_prod, reset) {
	var url = "/inc/ajax.products-compare.php";

	$.get(url, { id_prod: id_prod, rst: reset, sid: Math.random() },
		function(data) {
			$("#cmpbar").html(data);
			$("#cmpbar").show('fast');
			});
	$.get(url, { id_prod: id_prod, getcnt: 'true', sid: Math.random() },
		function(data) {
			$("#cmpcnt").html(data);
			$("#cmpcnt").show();
			});
	}

function addToCompare(id) {
	var url = "/inc/ajax.products-compare.php";

	$.get(url, { id: id, sid: Math.random() },
		function(data) {
			//$("#cmpbar").html(data);
			//$("#cmpbar").show('fast');
			});
	}

function searchQuery(string) {
	var url = "/inc/ajax.hledani.php";

	$.get(url, { search: string, sid: Math.random() },
		function(data) {
			$("#searchresults").html(data);
			});
	}

