/*** Creation date: 26.June, 2009 ***/

jQuery(document).ready(function() {

 $("#qField").attr("autocomplete","off"); 

 if($('.kwicks').length>0)
 {
 	//shAddScript("/scripts/jquery.kwicks-1.5.1.pack.js");
 	//$.getScript("jquery.kwicks-1.5.1.pack.js");

  $('.kwicks').kwicks({  
         max : 320,
         spacing : 1
     });  
 }

  var api = $("#overlay").overlay({api:true}); 
  window.openOverlay = function(id) { 
     $(".wrap").load("/includes/updateContent.php?id="+id);
	  
        api.load(); 
    } 

 // Searcher ... 
 $("#qField").click(function(){
  var valcek;
  valcek = $("#qField").val();
  if(valcek == "Search...")
    $("#qField").val("");
 });
 
 $(".submitBox").click(function(){
  var q;
  q = $("#qField").val();
  $("#searchResults").load("/includes/searchSite.php?q="+q);
 });

 $('#qField').bind('keyup', function(e) {
	  var q;
	  q = $("#qField").val();
    if(e.keyCode==38)
    {
     $("#searchBox li.over").removeClass('over').prev().addClass('over');
     if($("#searchBox li.over").length<1)
      $("#searchBox li:last").addClass('over');
    }
    else if(e.keyCode==40)
    {
     $("#searchBox li.over").removeClass('over').next().addClass('over');
     if($("#searchBox li.over").length<1)
      $("#searchBox li:first").addClass('over');
    }
    else if(e.keyCode == 13)
    {
     var theUrl= $("#searchBox li.over a").attr('href');
     if(theUrl.length>1)
       location.href = theUrl;
    }
    else
    {
     if(q.length > 1)
		   $("#searchResults").load("/includes/searchSite.php?q="+q);
     else if(e.keyCode==13)
			 $("#searchResults").load("/includes/searchSite.php?q="+q);
  	 else if(q.length == 0)
  		 $("#searchResults").empty();
   }

});

 // Rating ...
 if($('input.wow').length > 0)
   $('input.wow').rating(); 


 // Tabs ...
 $("#sm1").click(function() {
  $("#sm_tab1").show();  
  $("#sm_tab2").hide();  
  $("#sm_tab3").hide();  
  $("#sm_tab4").hide();
  $("#selectorMenu > li").removeClass("overButton");
  $("#sm1").addClass("overButton");
 }); 
 
 $("#sm2").click(function() {
  $("#sm_tab1").hide();  
  $("#sm_tab2").show();  
  $("#sm_tab3").hide();  
  $("#sm_tab4").hide();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 

 $("#sm3").click(function() {
  $("#sm_tab1").hide();  
  $("#sm_tab2").hide();  
  $("#sm_tab3").show();  
  $("#sm_tab4").hide();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 
 
 $("#sm4").click(function() {
  $("#sm_tab1").hide();  
  $("#sm_tab2").hide();  
  $("#sm_tab3").hide();  
  $("#sm_tab4").show();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 

 $("#sm1a").click(function() {
  $("#sm_tab1a").show();  
  $("#sm_tab2a").hide();  
  $("#sm_tab3a").hide();  
  $("#sm_tab4a").hide();
  $("#selectorMenu > li").removeClass("overButton");
  $("#sm1").addClass("overButton");
 }); 
 
 $("#sm2a").click(function() {
  $("#sm_tab1a").hide();  
  $("#sm_tab2a").show();  
  $("#sm_tab3a").hide();  
  $("#sm_tab4a").hide();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 

 $("#sm3a").click(function() {
  $("#sm_tab1a").hide();  
  $("#sm_tab2a").hide();  
  $("#sm_tab3a").show();  
  $("#sm_tab4a").hide();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 
 
 $("#sm4a").click(function() {
  $("#sm_tab1a").hide();  
  $("#sm_tab2a").hide();  
  $("#sm_tab3a").hide();  
  $("#sm_tab4a").show();  
  $("#selectorMenu > li").removeClass("overButton");
  $(this).addClass("overButton");
 }); 

 if($('textarea.tinymce').length > 0)
 {
 	
  $('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : '/scripts/tiny_mce/tiny_mce.js',

			// General options
			theme : "advanced",
	    plugins : "safari,pagebreak,style,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,bbcode",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
      theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cleanup,removeformat,|,sub,sup,|,charmap,emotions,media",
	    theme_advanced_buttons3 : "",
    
    	theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",

      theme_advanced_toolbar_location : "top",
	    theme_advanced_toolbar_align : "left",
	    theme_advanced_statusbar_location : "bottom",
	    theme_advanced_resizing : true
		});
 }
  
  if($('#subList').length > 0)
  {
   $('#subList').listnav({
     flagDisabled:true
   });
  }
 
 if($("#mycarousel").length >0)
 {
  $("#mycarousel").show();
  $('#mycarousel').jcarousel({});     
 }

 // Rotate Image ...
 if($("#imageTicker").length >0)
   $("#imageTicker").slideDown().newsticker();

});  

function clearField()
{
$("#searchResults").empty();
}

function addReply(id,obj,url,tid)
{
 $("#replyID").val(id);
 //$("#newPost").clone().insertAfter(obj);
 $(obj).next().load("/forum/insertReply/"+id+"/?url="+url+"&tid="+tid);
}

function addFavourites(id)
{
 $("#favourites").load("/includes/addFavourites.php?id="+id);
}

function giveVote(id,rate)
{
 $("#showRate").load("/includes/giveVote.php?id="+id+"&rate="+rate);
}

function showWallz(m_url)
{
 window.location = m_url;
}

function submitForma()
{
  var str = $('form').serialize();
  $.post("/includes/updateContent.php",str,function(data){
      $('.wrap').html(data);
  });
 
}


// Old stuff ...

function showComments(id,page)
{
 xmlhttp.open("GET", "/includes/updateComments.php?id="+id+"&page="+page,true);
 xmlhttp.onreadystatechange=function() 
 {
  if (xmlhttp.readyState==4) 
  {
   new_data = xmlhttp.responseText
   if(new_data != old_data)
     getObjById("commentList").innerHTML = xmlhttp.responseText;
   old_data = new_data
  }
 }
 xmlhttp.send(null);
}

/******************************
 **                          **
 **     Chat Functions       **
 **                          **
 ******************************/
function InitChat()
{
 DrawChatText();
 setTimeout("InitChat()", 5000);
}

function DrawChatText()
{
 $("#boks").load("/includes/show_chat.php");
}

function setChatChannel(id)
{
 if(!id)
  return;

 $("#boks").load("GET", "/includes/show_chat.php?channel="+id);
}

function put_smiley(code,txt)
{
 var mtxt = $("#chatField").val();
 $("#chatField").val(mtxt+' '+code);
}

function shAddScript(source){
    $.getScript(source, function(){
        alert(source + " loaded"); 
    })
};