$(function() {
	$(".column").sortable({
		connectWith: '.column',
		revert: true,
		cursor: 'move',
		
		stop: function() { 
		var sloupec = 1;
		$(".column").each(function(){
			
			var order = $(this).sortable("toArray");
			//$("#info").load("process-sortable.php?test="+order+"&sloupec="+sloupec);
			
			$.ajax({
				type: "POST",
				url: "process-sortable.php",
				data: "content="+order+"&sloupec="+sloupec,
				//success: function(html){
				//	$("#info_process").html(html);
				//}
			});

			sloupec++
		});
	}	
	});
	
	$(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
		.find(".portlet-header")
			.addClass("ui-widget-header ui-corner-all")
			//.prepend('<span class="ui-icon ui-icon-minusthick"></span>')
			.end()
		.find(".portlet-content");

	$(".portlet-header .ui-icon").click(function() {
		//$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
		$(this).parents(".portlet:first").find(".portlet-content").toggle();
	});

	$(".column").disableSelection();
});

$(document).ready(function() {
	$('#zabava_email_send').click(function() {
		//$("#button_zaregistrovat").hide();
		
		$.ajax({
			type: "POST",
			url: "/ac_email.php",
			data: "ac=zabava_send&recipient="+$('#form_zabava_email_prijemce').val()+"&sender="+$('#form_zabava_email_odesilatel').val()+"&komentar="+$('textarea#form_zabava_email_komentar').val()+"&odkaz="+$('#form_zabava_email_odkaz').val(),
			success: function(html){
				$("#info_process_send_email_zabava").html(html);
			}
		});
	});
});

$(function() {
	$("button, input:submit, ", ".hlavni").button();
});

$(document).ready(function(){
	$("#button_registrace").colorbox({iframe:true, width:"283px", height:"390px"});
	$("#button_zapomenute_heslo").colorbox({iframe:true, width:"285px", height:"245px"});
	$("#kontakty").colorbox({inline:true, width:"450px", height:"60%"});
	$("#kontakty_footpanel").colorbox({inline:true, width:"450px", height:"60%"});
	$("#kontakty_novy_footpanel").colorbox({inline:true, width:"310px", height:"270px"});
	$("#kontakty_novy").colorbox({inline:true, width:"310px", height:"270px"});
});

$.fx.speeds._default = 1000;
$(function() {
	$('#dialog_mail_odkaz_tapeta').dialog({
		autoOpen: false,
		modal: true,
		show: 'blind',
		hide: 'blind',
		position: 'center',
		width: 344,
		height: 455
	});
	
	$('#button_mail_odkaz_tapeta').click(function() {
		$('#dialog_mail_odkaz_tapeta').dialog('open');
		return false;
	});
});

$.fx.speeds._default = 1000;
$(function() {
	$('#dialog_zabava_email').dialog({
		autoOpen: false,
		modal: true,
		show: 'blind',
		hide: 'blind',
		position: 'center',
		width: 400,
		height: 330
	});
	
	$('#button_zabava_email').click(function() {
		$('#dialog_zabava_email').dialog('open');
		return false;
	});
});

/* Kontakty */
$(document).ready(function(){
	$("#form_kontakty_new").submit(function(){
		$.post("./../ac.php?ac=kontakt_new", $("#form_kontakty_new").serialize(), function(data){
			if(data == "true"){
				$("#kontakt_jmeno").attr("value", '');
				$("#kontakt_prijmeni").attr("value", '');
				$("#kontakt_tel_cislo").attr("value", '');
				$("#kontakt_email").attr("value", '');
				
				$.gritter.add({
					title: 'Kontakty',
					text: 'Kontakt byl úspěšně uložen!',
					sticky: false,
					time: '',
					class_name: 'gritter-light'
				});
				
				$("#kontakty_div_load").load("/kontakty_load.php");
				$.colorbox({inline: true, width:'450px', height:'60%', href:'#kontakty_div', title:'Kontakty'});
				return false;
			}
			
			if(data == "false"){
				$.gritter.add({
					title: 'Kontakty',
					text: 'Kontakt se nepodařilo uložit, opakujte prosím později.',
					sticky: false,
					time: '',
					class_name: 'gritter-light'
				});
				return false;
			}
			
			if(data == "false_empty"){
				$.gritter.add({
					title: 'Kontakty',
					text: 'Nejsou vyplněny žádné údaje!',
					sticky: false,
					time: '',
					class_name: 'gritter-light'
				});
				return false;
			}
		});
		return false;
	});
});

$(document).ready(function(){
	$("#form_kontakty_update").submit(function(){
		$.post("./../ac.php?ac=kontakty_update", $("#form_kontakty_update").serialize(), function(data){
			if(data == "true"){
				$.gritter.add({
					title: 'Kontakty',
					text: 'Kontakt byl úspěšně změněn!',
					sticky: false,
					time: '',
					class_name: 'gritter-light'
				});
				
				$("#kontakty_div_load").load("/kontakty_load.php");
				$.colorbox({inline: true, width:'450px', height:'60%', href:'#kontakty_div', title:'Kontakty'});
				return false;
			}
			
			if(data == "false"){
				$.gritter.add({
					title: 'Kontakty',
					text: 'Kontakt se nepodařilo změnit, opakujte prosím později.',
					sticky: false,
					time: '',
					class_name: 'gritter-light'
				});
				return false;
			}
		});
		return false;
	});
});
/* Kontakty */

/* Tooltip - tapety */
$(document).ready(function() {
$("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
	$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
			marginTop: '-70px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '-55px',
			top: '30%',
			left: '30%',
			width: '140px', /* Set new width */
			height: '110px', /* Set new height */
			padding: '8px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

	} , function() {
	$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
	$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '95px', /* Set width back to default */
			height: '65px', /* Set height back to default */
			padding: '5px'
		}, 400);
});
});

$(document).ready(function() {
	$("#show_tapety_kategorie img[title]").tooltip();
});

$(document).ready(function() {
	$("#show_tapety_uvod img[title]").tooltip();
});
/* Tooltip - tapety kategorie */

function open_window_tapety(tapeta,width,height,title,alt) {
	var window_tapety = window.open('','window_wallpaper','width='+width+',height='+height+',left=10,top=10,resizable=yes,menubar=no,toolbar=no,scrollbars=yes');
	window_tapety.document.open();
	window_tapety.document.writeln('<html>\n<head>\n <title>'+title+'</title>\n<meta HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-2">\n</head>\n <body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">');
	window_tapety.document.writeln('<img src="'+tapeta+'" title="'+alt+'" border="0" OnClick="window.close();" style="cursor: hand;">');
	window_tapety.document.writeln('</body>\n</html>');
	window_tapety.document.close();
}

/* Dialog erotika */
$(function() {
	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
	$( "#dialog" ).dialog( "destroy" );

	$( "#dialog-erotika" ).dialog({
		resizable: false,
		autoOpen: false,
		width: 600,
		height:410,
		modal: true,
		buttons: {
			"Pokračovat": function() {
				//$( this ).dialog( "close" );
				window.location = $('#dialog-erotika-open').attr('url_redir_dialog');
			},
			"Odejít": function() {
				$( this ).dialog( "close" );
			}
		}
	});
});

$(function() {
	$('#dialog-erotika-open').click(function() {
		$('#dialog-erotika').dialog('open');
	});
});
/* Dialog erotika */

/* Fancybox - recepty */
$(document).ready(function() {
	$("a[rel=recepty_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});
/* Fancybox - recepty */

/* Tisk, e-mail recepty */
function open_window_recepty_tisk(id, odkud) {
	iMyWidth = (window.screen.width/2) - (400 + 10)
	iMyHeight = (window.screen.height/2) - (350 + 25)
	Fokus = window.open("/page_recepty_tisk.php?id=" + id + "&odkud=" + odkud + "", "game_window","height=700,width=800,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=yes");
	Fokus.focus();
}

function open_window_recepty_email(id, odkud) {
	iMyWidth = (window.screen.width/2) - (400 + 10)
	iMyHeight = (window.screen.height/2) - (350 + 25)
	Fokus = window.open("/page_recepty_email.php?id=" + id + "&odkud=" + odkud + "", "game_window","height=700,width=800,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
	Fokus.focus();
}
/* Tisk, e-mail recepty */

/* Share */
$(function() {
	$( "#dialog:ui-dialog" ).dialog( "destroy" );

	$( "#dialog-message-kredit" ).dialog({
		modal: true,
		autoOpen: false,
		//position: 'bottom',
		width: 865,
		height: 440,
		zIndex: 9999,
		buttons: {
			Ok: function() {
				$( this ).dialog( "close" );
			}
		}
	});
	
	$( "#open-dialog-kredit" ).click(function() {
		$( "#dialog-message-kredit" ).dialog( "open" );
		return false;
	});
});

$(function() {
	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
	$( "#dialog:ui-dialog" ).dialog( "destroy" );

	$( "#dialog-message-provize" ).dialog({
		modal: true,
		autoOpen: false,
		//position: 'bottom',
		width: 450,
		height: 470,
		zIndex: 9999
		//buttons: {
		//	Ok: function() {
		//		$( this ).dialog( "close" );
		//	}
		//}
	});
	
	$( "#open-dialog-provize" ).click(function() {
		$( "#dialog-message-provize" ).dialog( "open" );
		return false;
	});
});
/* Share */

/* SMS */
$(document).ready(function(){
	$("#kontakty_div_load").load("/kontakty_load.php");
});
/* SMS */
