//rc
if(jQuery) (function(){
	$.extend($.fn, {
		rightClick: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					var evt = e;
					$(this).mouseup( function() {
						$(this).unbind('mouseup');
						if( evt.button == 2 ) {
							handler.call( $(this), evt );
							return false;
							
						} else {
							return true;
						}
					});
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		rightMouseDown: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					if( e.button == 2 ) {
						handler.call( $(this), e );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		rightMouseUp: function(handler) {
			$(this).each( function() {
				$(this).mouseup( function(e) {
					if( e.button == 2 ) {
						handler.call( $(this), e );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		noContext: function() {
			$(this).each( function() {
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		}
	});
})(jQuery);
//cookie
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function(){

 $("html, body").noContext();

    $.fn.exists = function(){
    	return $(this).length>0;
    	return $(this)=obj;
    }

    $.fn.unexists = function(){
    	return $(this).length==0;
    	return $(this)!=obj;

    }

    $("#nav a").mousedown(function(){
      $("#homeurl").show();
    });




$("a[href='#']").attr("href", "javascript:;");

     $(".loadfile a").live('click', function(){
	 	if($(this).hasClass("active")){}
		else{
				$("#nav .parent").removeClass("active");
				$(this).parents(".loadfile").find("a").removeClass("active");
				$(this).addClass("active");
		     	var file = $(this).attr("href");

				$("#content").hide();
                $("#content").html("");

		        $("#loading").css({"visibility":"visible"});
		        $("#content").load(file, function(){
					window.scroll(0,0);
                	$("#content").show();
                    $("#content img:last").load(function(){
                       $("#loading").css({"visibility":"hidden"});
					})

				});
		}

      return false
	 });



$(".items a").live('click', function(){
	active_item = $(this);								 
	$(".stopLoading").removeClass("stopLoading");
    $("#overlay").show();
	$("#loading").css({"visibility":"visible"});
	var curr = $(this);
    var mImg = $(this).attr("href");
    var o_dot = $(this);
    var mImage = new Image();
    document.getElementById('modal').appendChild(mImage);
    mImage.onload = function(){
         if($(".stopLoading").unexists()){
		         var mWidth = this.offsetWidth;
		         var mHeight = this.offsetHeight;
		         $("#modal").css("top", (o_dot.offset().top + 'px'));
		         $("#modal").css("left", (o_dot.offset().left + 'px'));
		         $("#modal").css("width", (curr.width() + 'px'));
		         $("#modal").css("height", (curr.height() + 'px'));
		         $("#modal img").css("width", "100%");
		         $("#modal img").css("height", "100%");
				 $("#loading").css({"visibility":"hidden"});
		         var top_final_place = $(window).scrollTop() + $(window).height()/2 - mHeight/2;
				 
				 $("#modal").css("visibility", "visible");
				 active_item.hide();
		         $("#modal").animate({width:mWidth, height:mHeight, left:$(window).width()/2-mWidth/2, top: top_final_place}, 'slow', function(){
		            $("#modal").append("<span class='closeModal' onclick='close_modal()'>Затвори</span>");
		            $("#modal").css("border", "solid 4px #fff");
		         });
		 }

    }
    mImage.src=mImg;
    return false;
});









});








function close_modal(){
	active_item.show();
	$("body").addClass("stopLoading");
   $("#modal").css("visibility", "hidden").empty().removeAttr("style");
   $("#overlay").hide();
   $("#loading").css("visibility", "hidden");
}

































