// starting the script on page load
$(document).ready(function()
	{
	initInputdesign();
	initTooltip();
	initMenu();
	initPicControls();	
	initFormValidate();
	initDragPostBox();
	allowComment();
	initPoll();
	
	$("a.closeAlert").click(function() { $(this).parent().animate({height:"hide",opacity: "0"}, { "duration": 300, "easing": "easeout" }); });

	alertTemp= $(".alertMessage p").html();
	errorTemp= $(".errorMessage p").html();
	
	if (alertTemp) $(".alertMessage").slideDown();
	if (errorTemp) $(".errorMessage").slideDown();
	});

$(window).bind("load",function()
	{
	$(".cB").css("visibility","visible");
	});

function minimize(divid)
	{
	if ($("#"+divid+"a").hasClass("min"))
		{
		$("#"+divid).hide();

		var date = new Date();
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000)); // 365 days
		$.cookie(divid, 'min', { path: '/', expires: date });
		  
		$("#"+divid+"a").removeClass("min");
		$("#"+divid+"a").addClass("max");
		} else
		{
		$("#"+divid).show();			
		// REMOVE COOKIE
		$.cookie(divid, null);
		  
		$("#"+divid+"a").removeClass("max");
		$("#"+divid+"a").addClass("min");
		$("#pollcontainer").show();
		}
	}
	
function allowComment()
	{
//	$(".primary").show();
	}	

function initPoll()
	{	
	// Just display results
	if ($.cookie('alreadyvoted')) 
		{
		$("#pollcontainer div.ptext").css("cursor", "default");				
		$.ajax({
				type: "POST",
				url: "/pages/ajax/poll_save_vote.php",
				success: function( data, status ) 
					{
					widths=data.split(",");
					$("#allvotes").html("Összesen "+ widths[7] +" szavazat");
					$("#res1").animate({ 
							  width: widths[0]
							}, { "duration": 500, "easing": "easeout" } );
	
					$("#res2").animate({ 
							  width: widths[1]
							}, { "duration": 500, "easing": "easeout" } );
					$("#res3").animate({ 
							  width: widths[2]
							}, { "duration": 500, "easing": "easeout" } );
					$("#res4").animate({ 
							  width: widths[3]
							}, { "duration": 500, "easing": "easeout" } );
					$("#res5").animate({ 
							  width: widths[4]
							}, { "duration": 500, "easing": "easeout" } );
					$("#res6").animate({ 
							  width: widths[5]
							}, { "duration": 500, "easing": "easeout" } );	
					}
				});			
		} else
		{
		// Set hover, click
		$("#pollcontainer div.pbg").hover(function() 
			{	
			$(this).animate({ 
			  backgroundColor: "#CCC"
			}, { "duration": 100} );		
			},function() 
			{
			$(this).animate({ 
			  backgroundColor: "#EEE"
			}, { "duration": 100} );			
			});		
		
	$("#pollcontainer div.ptext").click(function() 
			{	
			var post="vote="+$(this).attr("id");
			if(!$.cookie('alreadyvoted'))
				{		
				$.ajax({
					type: "POST",
					url: "/pages/ajax/poll_save_vote.php",
					data: post,
					success: function( data, status ) 
						{
						widths=data.split(",");
						$("#allvotes").html("Összesen "+ widths[7] +" szavazat");
						$.cookie('alreadyvoted', widths[6], { expires: 21, path: '/' });
						
						$("#res1").animate({ 
								  width: widths[0]
								}, { "duration": 500, "easing": "easeout" } );
		
						$("#res2").animate({ 
								  width: widths[1]
								}, { "duration": 500, "easing": "easeout" } );
						$("#res3").animate({ 
								  width: widths[2]
								}, { "duration": 500, "easing": "easeout" } );
						$("#res4").animate({ 
								  width: widths[3]
								}, { "duration": 500, "easing": "easeout" } );
						$("#res5").animate({ 
								  width: widths[4]
								}, { "duration": 500, "easing": "easeout" } );
						$("#res6").animate({ 
								  width: widths[5]
								}, { "duration": 500, "easing": "easeout" } );
						}					
					});
				}
			});
		}
	}	

function initDragPostBox()
	{
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { }
	 else
		{
		$('.sendPost').Drags({
				handler: 'h1',
				onMove: function(e) 
					{
					if(!$.browser.mozilla)
						{
						$("#commentForm").css("visibility","hidden");  
						$("#newPrivForm").css("visibility","hidden");  
						$("#newPubForm").css("visibility","hidden"); 
						$("#newBlogForm").css("visibility","hidden"); 	
						$("#newTopicForm").css("visibility","hidden"); 		
						$("#newPostForm").css("visibility","hidden"); 								
						}
					},
				onDrop:function(e) 
					{
					if(!$.browser.mozilla)
						{						
						$("#commentForm").css("visibility","visible"); 
						$("#newPrivForm").css("visibility","visible"); 
						$("#newPubForm").css("visibility","visible");  
						$("#newBlogForm").css("visibility","visible");  	
						$("#newTopicForm").css("visibility","visible"); 
						$("#newPostForm").css("visibility","visible"); 								
						}
					}
			});
		}
	}
	

function initPicControls()
	{
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { $("#piccontrols").hide(); }
	 else
	 {
	$("#piccontainer").hover(function() 
		{	
		$("#piccontrols").slideDown();
		},function() 
		{
		$("#piccontrols").slideUp();
		});	
	 }
	}	
	
function initRightToolbox()
	{
	$(".icon").fadeTo(1000, 1);
	
	$(".icon").hover(function() 
		{		
		$(this).fadeTo(100, 1);
		},function() 
		{
		$(this).fadeTo(200, 1);
		});	
	}

function initTooltip()
	{	
	$('.tooltip').tooltip({ 
    track: true, 
    delay: 0, 
    showURL: false, 
    showBody: " - ", 
    fade: 250 
	});
	
	$('.mover').css("cursor","move");
}


function initMenu()
	{	
	$("#header_menu a").hover(function() 
		{
		$(this).animate({
				marginTop:0
			}, 100);

		},function() 
		{
		$(this).animate({
				marginTop:-6	
			}, 100);
		});
}

 function initInputdesign()
	{	
	// INPUT DESIGN

	$("input[type='text'],input[type='password'],textarea").focus(function()
		{
		if ($(this).hasClass("primary")) {} else			
		$(this).css("border","1px solid #c55b15").css("backgroundColor","#F0F0F0");
		});
	
	$("input[type='text'],input[type='password'],textarea").blur(function()
		{
		if ($(this).hasClass("primary")) {} else			
		$(this).css("border","1px solid #A0A0A0").css("backgroundColor","#FFFFFF");
		});
	
	// CHECKBOX DESIGN
	$('input[type="checkbox"]').each(function() 
			{
			$(this).hide();	
			id=$(this).attr("id");	
			if($(this).attr("checked")==true)
				{
				$("<div id='cpic"+id+"' class='checkboxpicOn'></div>").insertAfter($(this));
				} else
				{
				$("<div id='cpic"+id+"' class='checkboxpic'></div>").insertAfter($(this));					
				}
			});
	
	$('div[id^="cpic"]').click(function()
		{
		inputid=$(this).attr("id").substr(4);
		if ($(this).attr("className")=="checkboxpic") 
			{
			$(this).attr("className","checkboxpicOn");
		
			$("#"+inputid).attr("checked","true");
			} else 
			{
			$(this).attr("className","checkboxpic");
			$("#"+inputid).attr("checked","");	
			}
		});

	};	

function displayType(typeId)
	{
	if (typeId==999) { $(".subhide").hide();} else { $(".subhide").show(); }
	selectId="subtype"+typeId;
	for(i=0;i<7;i++)
		{
		$("#subtype"+i).hide();
		}
	$("#"+selectId).show();
	}

	
jQuery.fn.shake = function(intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
  this.each(function() {
    $(this).css({position:'relative'});
    for (var x=1; x<=intShakes; x++) {
      $(this).animate({left:(intDistance*-1)}, (((intDuration/intShakes)/4)))
      .animate({left:intDistance}, ((intDuration/intShakes)/2))
      .animate({left:0}, (((intDuration/intShakes)/4)));
    }
  });
  return this;
};

function verifyLogin()
	{
	var post="uname="+$(".lun").val()+"&pass="+$(".lpa").val();	
	$.ajax({
		type: "POST",
		url: "/pages/ajax/verifyLogin.php",
		data: post,
		success: function( data, status ) 
			{ 
			if(data=="valid_login") { $("#loginform").submit(); } else 
				{
				$("#logArea").shake(3, 6, 300);
				setTimeout("document.location='/_bejelentkezes?hiba'",400);
				}
		 	}
		});
	}	

function reportIt(type,id)
	{
	var post="type="+type+"&id="+id;
	$.blockUI({ message: '<p style=\'text-align:center; padding:16px;\'>Köszönjük, hogy jelentetted!</p>',
				 fadeIn: 200, 
			    fadeOut: 300, 
				css: { width: '460px', top:  '20%', left: ($(window).width() - 460) /2 + 'px', padding:'0px', margin:'0px', textAlign:'left', border:'1px solid #777' } ,
				overlayCSS:  { backgroundColor:'#000', opacity: '0.5' }
				 });
	setTimeout("$.unblockUI()",2000);
	$('.blockOverlay').click($.unblockUI);		
	$.ajax({
		type: "POST",
		url: "/pages/ajax/reportIt.php",
		data: post
		});
	}
	
function showPostEdit(divId, wdt)
	{
	if (typeof(wdt)!="number") wdt=480;
	lft=($(window).width() - parseInt(wdt)) /2 + 'px';

	$.blockUI({ message: $('#'+divId), 
				fadeIn: 200, 
			   fadeOut: 300, 
				css: { width: parseInt(wdt), top:  '20%', left: lft, padding:'0px', margin:'0px', textAlign:'left', border:'0px solid #444', backgroundColor:'transparent' } ,
				overlayCSS:  { backgroundColor:'#000', opacity: '0.5' }
				}); 
	//$('.blockOverlay').click($.unblockUI);	
	}
	
function hidePostEdit()
	{
	dom=document.location;
	$.unblockUI();
	setTimeout("document.location='"+dom+"'",400);
	}	
	
function FCKeditor_OnComplete(instance) 
	{
//	if (instance.Name=="commentContent") $('.editComment').show();
	}

function editComment(commentId)
	{
	$("#editCommentId").val(commentId);
	id="#post"+commentId+" .content";
	temp=$(id).html();

	var oEditor = FCKeditorAPI.GetInstance('commentContent'); 
	if (!oEditor) { $('.editComment').hide(); } else
		{
		oEditor.SetHTML(temp);
		$("#newComment").slideDown();
		}
	}
	
function confirmPostDelete(id)
	{
	$("#deletePostId").val(id);
	showDialog("Biztos, hogy törlöd ezt a hozzászólást?","Igen","Nem"," $('#deletePostForm').submit(); ","$.unblockUI()",0);
	}	

	
function confirmCommentDelete(id)
	{
	$("#deleteCommentId").val(id);
	showDialog("Biztos, hogy törlöd ezt a hozzászólást?","Igen","Nem"," $('#deleteCommentForm').submit(); ","$.unblockUI()",0);
	}	
	
function confirmVideoDelete()
	{
	showDialog("Biztos, hogy törlöd ezt a videót?","Igen","Nem"," $('#deleteVideoForm').submit(); ","$.unblockUI()",0);
	}	
	
function confirmPictureDelete()
	{
	showDialog("Biztos, hogy törlöd ezt a képet?","Igen","Nem"," $('#deletePictureForm').submit(); ","$.unblockUI()",0);
	}	
	
function confirmBlogDelete()
	{
	showDialog("Biztos, hogy törlöd ezt a blogot?","Igen","Nem"," $('#deleteBlogForm').submit(); ","$.unblockUI()",0);
	}	
	
function showDialog(vh1,v1,v2,func1,func2,timeout)
	{
	if (vh1=="") { $("#md h1").hide(); } else { $("#md h1").html(vh1); }
	if (v1=="") { $("#amd1").hide(); } else { $("#amd1").html(v1); }
	if (v2=="") { $("#amd2").hide(); } else { $("#amd2").html(v2); }
	
	$("#amd1").click(function() 
		{
		var tmpFunc = new Function(func1);
		tmpFunc();
		return false;
		});
	$("#amd2").click(function() 
		{
		var tmpFunc = new Function(func2);
		tmpFunc();
		return false;
		});	

	if (timeout>0) {setTimeout(" $.unblockUI(); ", timeout);}
	
	$.blockUI({ message: $('#md'), 
				fadeIn: 200, 
			   fadeOut: 300, 
				css: { width: '350px', top:  '20%', left: ($(window).width() - 350) /2 + 'px', padding:'0px', margin:'0px', textAlign:'left', border:'1px solid #333',backgroundColor:'#fff9ec' } ,
				overlayCSS:  { backgroundColor:'#000', opacity: '0.5' }
				}); 
	$('.blockOverlay').click($.unblockUI);	
	}
	
function showProfPicUpload()
	{
	$('#new_picture').slideDown();
	}
	
	
function confirmUserDelete()
	{
	showDialog("Biztos, hogy törlöd a felhasználód és állatait?","Igen, törlöm","Nem"," $('#deleteUserForm').submit() ","$.unblockUI()",0);
	}
	
function confirmContestPicDelete()
	{
	showDialog("Biztos, hogy törlöd a képet?","Igen, törlöm","Nem"," $('#deleteContestPicForm').submit() ","$.unblockUI()",0);
	}	
	
	
function confirmPetDelete(name,id)
	{
	showDialog("Amennyiben "+name+" már nincs közöttünk, tartsd meg profilját, de halálát jelezd az adatainál. Biztos, hogy törlöd?","Igen, törlöm","Nem"," $('#deletePetForm"+id+"').submit() ","$.unblockUI()",0);
	}	

function showPreview(coords)
	{
		var rx = 80 / coords.w;
		var ry = 80 / coords.h;
		
		$("#x").val(coords.x);
		$("#y").val(coords.y);
		$("#w").val(coords.w);
		$("#h").val(coords.h);												

	bigW=$("#bigPicture").width();
	bigH=$("#bigPicture").height();
		
		jQuery('#preview').css({
			width: Math.round(rx * bigW) + 'px',
			height: Math.round(ry * bigH) + 'px',
			marginLeft: '-' + Math.round(rx * coords.x) + 'px',
			marginTop: '-' + Math.round(ry * coords.y) + 'px'
		});
	}
	
 function CreateBookmark(title, url) 
 {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { // Opera Hotlist
        return true; }
 }	
 
 	
function confirmSilence()
	{
	showDialog("Biztos, hogy letiltod?<br /><span style=\"font-size:10px;\">(A felhasználó semelyik állata nem fog tudni többé privát üzenetet küldeni neked vagy az oldalaidon hozzászólást írni!)</span>","Igen","Nem"," $('#silenceForm').submit(); ","$.unblockUI()",0);
	}	
	
 
 	
function confirmDeSilence()
	{
	showDialog("Biztos, hogy engedélyezed, hogy kapcsolatba lépjen Veled?","Igen","Nem"," $('#silenceForm').submit(); ","$.unblockUI()",0);
	}		
	