﻿
$(document).ready(function(){
	$(window).ready(function() {
		var vysl = 'div#video';
		$(vysl).html('<img src="http://www.galacticheal.com/img/wait_16x16.gif" border="0" alt="načítání" title="načítání"> Odesílá se');
		$.ajax({
			type: 'POST',
			url: 'http://www.galacticheal.com/inc/process.php',
			data: "akce=video&h=" + $("input#h").val(),
			success: function(msg) {
				$(vysl).html(msg);
			}
		});
		return false;
	});
	

	$.extend({
	  password: function (length, special) {
		var iteration = 0;
		var password = "";
		var randomNumber;
		if(special == undefined){
			var special = false;
		}
		while(iteration < length){
			randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
			if(!special){
				if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
				if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
				if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
				if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
			}
			iteration++;
			password += String.fromCharCode(randomNumber);
		}
		return password;
	  }
	});


	// Accordion
	$("#accordion").accordion({ header: "h3" });

	$('form.ajax').submit(function() {
		var vysl = '#'+$(this).attr('vysledek');
		$(vysl).html('<img src="http://www.galacticheal.com/img/wait_16x16.gif" border="0" alt="načítání" title="načítání"> Odesílá se');
		$.ajax({
			type: 'POST',
			url: 'http://www.galacticheal.com/inc/process.php',
			data: $(this).serializeArray(),
			success: function(msg) {
				$(vysl).html(msg);
			}
		});
		return false;
	});
	
	$("a.ajax_gen_heslo").click(function(){
		$('#generovane_heslo').val($.password(6));
	});
	
	$("#btn_go").click(function(){
		window.top.location.href = $('#presmerovat_ajax').val();
	});
	
	$('#tabs').tabs({
		fx: { opacity: 'toggle'},
		speed: 'fast',
		cache: true
	});
 
	

	// Dialog			
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});
	
	$('#dialogs').dialog({
		height: 500,
		bgiframe: true,
		width: 900,
		minWidth: 200,
		minHeight: 100,
		resize: "auto",
		autoSize: true,
		autoResize: true,
		modal: true,
		show: 'scale',
		hide: 'scale',
		closeOnEscape: true,
		autoOpen: false,
		resizable: true,
		buttons: {
			'OK': function() {
				$(this).dialog('close');
				$('#flash-banner').show();
			}
		}
	});
	
	$("a#napoveda , a[rel='napoveda[]']").click(function() {
		var soubor = $(this).attr("href");
		cast = soubor.split("?");
		if (cast[1] == "" || cast[1] == undefined) {
			predat = "ajax=true&random=" + Math.random()*99999;
			web = soubor;
		} else {
			predat = cast[1] + "&ajax=true&random=" + Math.random()*99999;
			web = cast[0];
		}
			$.ajax({
				type: 'GET',
				url: web,
				data: predat,
				success: function(msg) {
					$("div#dialogs").html(msg).dialog("open");
					$('#flash-banner').hide();
				},
				error: function() {
					$("div#dialogs").html("<h1>Omlouváme se, nápověda nenalezena</h1><br><br><a href=\"http://www.irucz.ru/cz/nahlasit-chybu/\">Kontaktujte prosím administraci.</a>").dialog("open");
				}
			});
		return false;
	});
	
	$('a[href*=#]').click(function() {
    	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
	});

	// Dialog Link
	$('#dialog_link').click(function(){
		$('#dialog').dialog('open');
		return false;
	});

	// Datepicker
	$('#datepicker').datepicker({
		inline: true,
		altFormat: 'dd.mm.yy',
		dateFormat: 'dd.mm.yy'
	});
	$('#datepicker1').datepicker({
		inline: true,
		altFormat: 'dd.mm.yy',
		dateFormat: 'dd.mm.yy'
	});

	// Slider
	$('#slider').slider({
		range: true,
		values: [17, 67]
	});

	// Progressbar
	$("#progressbar").progressbar({
		value: 20 
	});

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);

});

