function explode(delimiter, string, limit) {
     var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||        delimiter === false ||
        delimiter === null ) {
        return false;
    }
     if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;    }
}


// jQuery INT Document
$(document).ready(function() {

//class "blank" - opening in new window
$(".blank").attr("target", "_blank");

//vertical align text
$("#main-menu .link").each(function(){ if($(this).find("span").height() < 20) { $(this).addClass("one"); } });

//menu hover
$("#main-menu .main").mouseenter(function(){
  $("#main-menu .main").removeClass("active"); 
  $(this).addClass("active"); 
  $("#main-menu .sub").fadeOut(200);
  $(this).find(".sub").fadeIn(200);
});
$("#main-menu .sub, #main-menu").mouseleave(function(){
  $("#main-menu .main").removeClass("active"); 
  $("#main-menu .sub").fadeOut(200);
});


//send email
$("a.email").toggle(function(){
  $(this).addClass("active");
  $("#article-send").html("");
  $("#article-send").append("<span>Vaše jméno: <input type='text' name='article-send-name' id='article-send-name' value='' /></span><span>E-mailová adresa příjemce: <input type='text' name='article-send-email' id='article-send-email' value='' /></span><a href='javascript:void(0)' title='Odeslat článek'>Odeslat</a>").slideDown();
  return false;
}, function(){
  $(this).removeClass("active");
  $("#article-send").slideUp();
  return false;
});
$("#article-send a").live("click", function(){    
  if ($("#article-send-name").val() != "") {
    var RegExpEmail = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExpEmail.test($("#article-send-email").val())){
        $("#article-send").html("Odesílá se ..."); 
        var id = explode("-", $("a.email").attr("id"));
        $.post("/ajax.php?do=email", {id : id[1], email : $("#article-send-email").val(), name : $("#article-send-name").val()}, function(data){
            $("#article-send").html(data); 
        });
    }else{
        alert("Zadaná e-mailová adresa není platná!");
    } 
  } else {
     alert("Je nutné zadat Vaše jméno!");
  }
});


//add download point
$(".filetype").click(function(){
   var id = explode("-", $(this).attr("id"));
   $.post("/ajax.php?do=download", {id : id[1]});
});


//start fancyzoom (fancybox.js)
$('.photos a').fancyzoom({scaleImg: true, closeOnClick: true, imgDir: '/images/fancyzoom/', showoverlay : false});  
  
});

