// ----------------------------------------------------------------------------
// markItUp!
// ----------------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// ----------------------------------------------------------------------------
// BBCode tags example
// http://en.wikipedia.org/wiki/Bbcode
// ----------------------------------------------------------------------------
// Feel free to add more tags
// ----------------------------------------------------------------------------
mySettings = {
	previewParserPath:	'/index.php?mod=forum&p=1', // path to your BBCode parser
    previewTemplatePath:'templates/preview.html',
	markupSet: [
		{name:'Félkövér', key:'B', openWith:'[b]', closeWith:'[/b]'},
		{name:'Dőlt', key:'I', openWith:'[i]', closeWith:'[/i]'},
		{name:'Aláhúzott', key:'U', openWith:'[u]', closeWith:'[/u]'},
		{name:'Áthúzott', key:'S', openWith:'[s]', closeWith:'[/s]'},
		{separator:'---------------' },
		{name:'Kép', key:'P', replaceWith:'[img][![Url]!][/img]'},
		{name:'YouTube videó beszúrása',  replaceWith:'[video][![Videó URL-je]!][/video]', className:'youtube'},
		{name:'Link', key:'L', openWith:'[url=[![Url]!]]', closeWith:'[/url]', placeHolder:'Link szövege', className:'addlink'},
		{separator:'---------------' },
		{	name:'Colors',
			className:'colors',
			openWith:'[color=[![Color]!]]',
			closeWith:'[/color]',
				dropMenu: [
					{name:'Sárga',	openWith:'[color=yellow]', 	closeWith:'[/color]', className:"col1-1" },
					{name:'Narancs',	openWith:'[color=orange]', 	closeWith:'[/color]', className:"col1-2" },
					{name:'Piros', 	openWith:'[color=red]', 	closeWith:'[/color]', className:"col1-3" },

					{name:'Kék', 	openWith:'[color=blue]', 	closeWith:'[/color]', className:"col2-1" },
					{name:'Lila', openWith:'[color=purple]', 	closeWith:'[/color]', className:"col2-2" },
					{name:'Zöld', 	openWith:'[color=green]', 	closeWith:'[/color]', className:"col2-3" },

					{name:'Fehér', 	openWith:'[color=white]', 	closeWith:'[/color]', className:"col3-1" },
					{name:'Szürke', 	openWith:'[color=gray]', 	closeWith:'[/color]', className:"col3-2" },
					{name:'Fekete',	openWith:'[color=black]', 	closeWith:'[/color]', className:"col3-3" }
				]
		},
  	{separator:'---------------' },
  	{name:'Mosoly', key:'', openWith:':-)', closeWith:'',className:"smile"},
  	{name:'Vigyor', key:'', openWith:':-D', closeWith:'',className:"smile3"},
  	{name:'Szomorú', key:'', openWith:':-(', closeWith:'',className:"smile2"},
  	{name:'S', key:'', openWith:':-S', closeWith:'',className:"smile4"},
  	{name:'P', key:'', openWith:':-P', closeWith:'',className:"smile5"},
  	{name:'Meglepő', key:'', openWith:':-O', closeWith:'',className:"smile6"},
  	{name:'Kacsintás', key:'', openWith:';-)', closeWith:'',className:"smile7"},
  	{name:'LOL', key:'', openWith:':lol:', closeWith:'',className:"smile8"},
  	{name:'Cool', key:'', openWith:':cool:', closeWith:'',className:"smile9"},
  	{name:'Cry', key:'', openWith:':cry:', closeWith:'',className:"smile10"},
  	{name:'Evil', key:'', openWith:':evil:', closeWith:'',className:"smile11"},
  	{name:'Roll Eyes', key:'', openWith:':roll:', closeWith:'',className:"smile12"},
    {name:'Előnézet', className:"preview", call:'preview' }
 	]
}

function insertAtCursor(myField, myValue) {
if (document.selection) {
	myField.focus();
	sel = document.selection.createRange();
	sel.text = myValue;
}
else if (myField.selectionStart || myField.selectionStart == 0) {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
// calling the function

function addlink()
{
cim=window.prompt("Kérlek add meg az oldal címét","http://");
if(cim==null){return false;}
link=window.prompt("Kérlek add meg a link nevét");
if(link==null){return false;}
insertAtCursor(document.getElementById('ptext'),"[url="+cim+"]"+link+"[/url]");
return false;
}

function addimg()
{
cim=window.prompt("Kérlek add meg a kép címét","http://");
if(cim==null){return false;}
insertAtCursor(document.getElementById('ptext'),"[img]"+cim+"[/img]");
return false;
}


function addbold()
{
insertAtCursor(document.getElementById('ptext'),"[b][/b]");
return false;
}

function addit(f)
{
insertAtCursor(document.getElementById('ptext'),"["+f+"][/"+f+"]");
return false;
}

$(document).ready(function()	{
	// Add markItUp! to your textarea in one line
	// $('textarea').markItUp( { Settings }, { OptionalExtraSettings } );
	$('#markItUp').markItUp(mySettings);

	// You can add content from anywhere in your page
	// $.markItUp( { Settings } );
	$('.add').click(function() {
 		$.markItUp( { 	openWith:'<opening tag>',
						closeWith:'<\/closing tag>',
						placeHolder:"New content"
					}
				);
 		return false;
	});

	// And you can add/remove markItUp! whenever you want
	// $(textarea).markItUpRemove();
	$('.toggle').click(function() {
		if ($("#markItUp.markItUpEditor").length === 1) {
 			$("#markItUp").markItUpRemove();
			$("span", this).text("get markItUp! back");
		} else {
			$('#markItUp').markItUp(mySettings);
			$("span", this).text("remove markItUp!");
		}
 		return false;
	});
});




$(function()
{



    $(".hidden").each(function()
    {
     $(this).hide();
    });

  function check1(){
    var ret=true;
    $("form.reg input[type=text]").each(function(){
      if($(this).val()=="" ){
        $("#dialog").dialog('open');
        ret = false;
        return false;
      }
    });
    return ret;
  if(ret)
  {
    $.get("/index.php","mod=reg&"+$("form.reg").serialize(),function(json){
      if(!json.ok){
        $("#text").html(json.errorstr);
        $("#dialog").dialog('open');
      }else{
        $("div.reg").html("<div class='ok'>"+json.msg+"</div>");
      }
    },"json");
  }
   return false;
  }

  $("body").append("<div class='edialog' title='Elfelejtett jelszó'><div id='etext'>"+
  "<form action='/index.php?mod=elf' id='elff'>'"+
  "<p><label for='email'>E-mail cím:&nbsp;</label><input type='text' name='email' id='email' /></p>"+
  "</form></div>"+
  "</div>");
  $("a.elf").bind("click",function(){
      $(".edialog").dialog('open');
      return false;
  });

  $(".edialog").dialog({
  autoOpen:false,
		bgiframe: true,
		modal: true,
		buttons: {
            Mégsem:function(){$(this).dialog('close');},
			Ok: function() {
				    $.get("/index.php","mod=elf&mail="+$("#email").val(),function(json){
                    if(json.ok){
                        $("#etext").html("Az új jelszót elküldtük az email címedre!");
                    }else{
                        alert(json.errorstr);
                    }
                    },"json" )
		      	}
		}
  });

  $("#dialog").dialog({
  autoOpen:false,
		bgiframe: true,
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
  });

  $("#belep").bind("click",function()
  {
    $.get("/index.php","mod=login&nev="+$("#login").val()+"&pass="+$("#pass").val(),function(json){
      if(!json.ok)
      {
        $("#text").html(json.errorstr);
        $("#dialog").dialog('open');
      }else{
        document.location="/index.php?mod=sel";
      }
    },"json");
    return false;
  });

  $("#loginform").bind("submit",function()
  {
    $.get("/index.php","mod=login&nev="+$("#login").val()+"&pass="+$("#pass").val(),function(json){
      if(!json.ok)
      {
        $("#text").html(json.errorstr);
        $("#dialog").dialog('open');
      }else{
        document.location="/index.php?mod=sel";
      }
    },"json");
    return false;
  });

  $("#nev").bind("blur",function(){
    if($(this).val()!="" )
    {
        $("#kari").attr("src","http://eu.wowarmory.com/character-model-embed.xml?r=Ragnaros&cn="+$(this).val()+"&rhtml=true");
        $("div.kari").show();
    }
  }
  );

  var t=500;
  function sh()
  {
      $("div.jel").toggle();
      setTimeout(sh,t);
      t=(t==2000?500:2000);
  }
  setTimeout(sh,500);
  $(document).pngFix();

  $("form.reg button").bind("click",check1);
  $("input, textarea").bind("focus",function(){$(this).addClass("aktiv");});
  $("input, textarea").bind("blur",function(){$(this).removeClass("aktiv");});

  $("input[type=checkbox]").bind("focus",function(){$(this).blur();});
  //$("div.jel").effect("pulsate",{times:5000},5000);

  $("a[target=_blank]").each(function()
  {
     var ref = new String($(this).attr("href"));
     if(( ref.indexOf(".jpg") != -1 ) || ( ref.indexOf(".png") != -1 ) )
     {
      $(this).bind("click",function(){return false;});
      $(this).attr("target","_self");
      $(this).colorbox({maxHeight:"98%"});
      var x = $(this).html();
      $(this).html("<div class='hidden' style='padding:10px;background-color:#EDD17C;border:1px solid #800000;margin-top:30px;display:none;position:absolute;text-align:center;width:150px;'>"+"<img width='150' src='"+ref+"' alt='"+x+"'/></div>"+x);
      $(this).mouseover(function(){
        $(this).children("div").fadeIn();
      }
      );
      $(this).mouseout(function(){
        $(this).children("div").fadeOut();

      });
     }
  });

  $(".fpost img").each(function() {

   var width = $(this).width();

   if (width > 400)
   {
     $(this).css("width", "400px");
     $(this).css("cursor","pointer");
     $(this).colorbox({href:$(this).attr("src"),maxHeight:"98%"});
   }

 });

  $("a[rel='gal']").each(function()
  {
    $(this).colorbox({transition:"fade",height:"98%"});
  });


  $("a").not(".cbox").each(function()
  {
    var href = new String ( $(this).attr("href") );
    if( href.indexOf("http://")>=0 )
    {
        if( ( href.indexOf(".jpg") == -1 ) && ( href.indexOf(".png") == -1 )  )
        {
           $(this).bind("click",function(){window.open($(this).attr("href"),"_");return false;});
        }
    }
  });

  $("a.cbox").each(function()
  {
    $(this).colorbox({iframe:true,width:363,height:660});
  });

  $("a.colorbox").colorbox({transition:"fade",height:"98%",
    current:"{current}. kép / {total}",
    previous:"&laquo;&nbsp;el?z?",
    next:"következő &raquo;",
    close:"Bezárás",
    speed:350,
    slideshowStop:"Diavetítés leállítása",
    slideshowStart:"Diavetítés"
  });

//  $("object").each(function(){$(this).append(" <param name='wmode' value='transparent'>"); } );

//  $("embed").attr("wmode","transparent");


  $.get("/index.php?mod=js",null,function(json){
        if(json.ok)
        {
            $("div.login").html("<p><a style='color:white' href='/index.php?mod=sel'>Belépés a tagok oldalára&nbsp;&gt;&gt;</a></p>");
            $("a.sa2").html("Kilépés");
            $("a.sa2").attr("href","/index.php?mod=logout");
            $("#btns").html('<div class="seldiv2"><button onclick="document.location=\'/index.php?mod=reg\';">&nbsp;Adataim</button></div><div class="seldiv2"><button onclick="window.open(\'http://www.roid.hu/dkp/listmembers.php\');">&nbsp;DKP Lista</button></div><div class="seldiv2"><button onclick="window.open(\'http://www.roid.hu/roidraid/\');">Raidek</button></div><div class="seldiv2"><button onclick="document.location=\'/index.php?mod=forum\';">Fórum</button></div>');
         }
  },"json");

  $("a.hszl").each(function(){
   $(this).bind("click",function(){
    var ids = new String($(this).attr("id") );
    var idk = ids.split("_");
    var id = idk[1];
    $.get("/index.php","mod=forum&q="+id,function(html){
        var tmp = $("#markItUp").val();
        tmp+=html;
        $("#markItUp").val(tmp);
    },"html");
//    var q = $("#fp_"+id).html();
//    var tmp = $("#markItUp").val();
//    tmp+="\n[q]"+q+"[/q]";
//    $("#markItUp").val(tmp);
    return true;
   });
  });

  function full(json){
        var x = "";
        $.each(json.ch,function(i,item){
            x+="<b>"+item.login+":</b> "+item.text+"<br />";
        });
        $(".chtext").html(x);
        try{

        var objDiv = document.getElementById("asdf");
        objDiv.scrollTop = objDiv.scrollHeight;
        $(".ucs").html("Utolsó: "+json.ls);

        }catch(e){}

  }

  $('.ch button').click(function(){
    $.get("index.php","mod=ch&cht="+$("#cht").val(),full,"json" );
    $("#cht").val("");
    return false;
  }
  );

  setInterval(function(){
    $.get("index.php","mod=ch",full,"json" );

  },5000
  );


      $('#cht').keyup(function(e) {

      if(e.keyCode == 13) {

            $('.ch button').click();

      }

      });

    $.get("index.php","mod=ch",full,"json" );



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

 var f = false;
 $(".title").click(
 function(){
    $("#hsd").slideToggle("normal",function(){
        f=!f;
        createCookie("open",f,20);
    });
 }
 );



/*
 if(readCookie("open")==true)
 {
    $("#hsd").show();
    f=true;
 }else{
    $("#hsd").hide();
    f=false;
 }
*/

/*

/////////////////////////////////////////////////
// HÓESÉS                                      //  
/////////////////////////////////////////////////

var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = "/js/snowstorm.js";
document.body.appendChild(script);

*/

});

