$(function() {
		var max = 0;
		$("label").each(function(){
				if ($(this).width() > max)
					max = $(this).width();   
		});
		$("label").width(max);
		
		
		$(".input-search").Watermark("Vyhledávání");
		$("#prijemce").Watermark("E-mail příjemce");
		$("#odesilatel").Watermark("Vaše jméno");
		$("#chci_jmeno").Watermark("Jméno a Příjmení");
		$("#chci_email").Watermark("E-mailová adresa");

	
  $('#container-1').tabs({ 
			fxFade: false, 
			fxSpeed: 'fast' 
		}); 
        
        $('#container-2').tabs({ 
            fxFade: true, 
            fxSpeed: 'slow' 
		});

        
        $("#tabs").tabs({
            event: 'mouseover'
        });

        
             
	$('#doporuc_box').hide();
	$("#doporuc").click(function(){
        $('#chciinfo_box').hide();
		$('#doporuc_box').toggle('blind', '', 500);		
	});
	
	$('#chciinfo_box').hide();
	$("#chci_info").click(function(){
        $('#doporuc_box').hide();
		$('#chciinfo_box').toggle('blind', '', 500);		
	});

	
/* chci pravidelne informace - prihlaseni | odhlaseni */
	$('.error').hide();
	
	$("#odeslat").click(function() {
		var prijemce = $("input#prijemce").val();
		if (prijemce == "E-mail příjemce") {
			$("p#prijemce_error").show();
			$("input#prijemce").focus();
			return false;
		}
		
		var odesilatel = $("input#odesilatel").val();
		if (odesilatel == "Vaše jméno") {
			$("p#odesilatel_error").show();
			$("input#odesilatel").focus();
			return false;
		}
		
		var stranka = $("input#stranka").val();
		
		var dataString = 'prijemce='+ prijemce + '&odesilatel=' + odesilatel + '&stranka=' + stranka;
		
		$.ajax({
		      type: "POST",
		      url: "http://www.bibs.cz/inc/sendform.php",
		      data: dataString,
		      success: function() {
			$('#doporuc_box').html("<div id='message'></div>");
			$('#message').html("<h3>Doporučení bylo odesláno</h3>")
		      }
		     });
		return false;
	});
	
	$("#prihlasit").click(function() {
		var name = $("input#chci_jmeno").val();
		if (name == "Jméno a Příjmení") {
			$("p#name_error").show();
			$("input#chci_jmeno").focus();
			return false;
		}
		
		var email = $("input#chci_email").val();
		if (email == "E-mailová adresa") {
			$("p#email_error").show();
			$("input#chci_email").focus();
			return false;
		}
		
		var prg1 = $("#chci_program_1:checked").val();
		var prg2 = $("#chci_program_2:checked").val();
		var prg3 = $("#chci_program_3:checked").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&typ=prihlasit&prg1=' + prg1 + '&prg2=' + prg2 + '&prg3=' + prg3;
		
		$.ajax({
		      type: "POST",
		      url: "http://www.bibs.cz/inc/process.php",
		      data: dataString,
		      success: function() {
			$('#chciinfo_box').html("<div id='message'></div>");
			$('#message').html("<h3>Děkujeme za Váš zájem</h3>")
			.append("<p>formulář byl odeslaný ke zpracování</p>");
		      }
		     });
		return false;
	});
	$("#odhlasit").click(function() {
		var name = $("input#chci_jmeno").val();
		if (name == "Jméno a Příjmení") {
			$("p#name_error").show();
			$("input#chci_jmeno").focus();
			return false;
		}
		var email = $("input#chci_email").val();
		if (email == "E-mailová adresa") {
			$("p#email_error").show();
			$("input#chci_email").focus();
			return false;
		}
		
		var prg1 = $("#chci_program_1:checked").val();
		var prg2 = $("#chci_program_2:checked").val();
		var prg3 = $("#chci_program_3:checked").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&typ=odhlasit&prg1=' + prg1 + '&prg2=' + prg2 + '&prg3=' + prg3;
		
		$.ajax({
		      type: "POST",
		      url: "http://www.bibs.cz/inc/process.php",
		      data: dataString,
		      success: function() {
			$('#chciinfo_box').html("<div id='message'></div>");
			$('#message').html("<h3>Děkujeme za Váš zájem</h3>")
			.append("<p>formulář byl odeslaný ke zpracování</p>");
		      }
		     });
		return false;
	});
	
	$("#accordion").accordion({ 
		header: "h3",
		collapsible: true,
		active: false,
		autoHeight: false
	});
    
    $("a[rel='example3']").colorbox({
        transition: "none",
        current: "foto {current} z {total}"  
    }); 
    
    
    $().bind('cbox_open', function(){
       $('object, embed').css({'visibility':'hidden'});
    }).bind('cbox_closed', function(){
       $('object, embed').css({'visibility':'inherit'});
    });
    
    
    
        var cat = $('#categorySelect');
        var el = $('#elementSelect');

        cat.selectChain({
            target: el,
            url: 'http://www.bibs.cz/select-chain.php',
            type: 'post',
            data: "ajax=true"
        }).trigger('change'); 
       
      
});



        
        $("#elementSelect").change(onSelectChange); 
    
        function onSelectChange(){         
            var selected = $("#elementSelect option:selected");       
            var output = "";
            $("#output").load("http://www.bibs.cz/rpc.php?o="+selected.val()+"");

        }

/*
$(window).bind("load", function() { 
	$("div#basic").slideViewerPro({
		galBorderWidth: 1,
		galBorderColor: "#000",
		thumbsActiveBorderColor: "#999",
		thumbs: 5,
		thumbsPercentReduction: 27,
		leftButtonInner: "&laquo;",  
		rightButtonInner: "&raquo;"
	}); 
});
*/
