
function insertAtCursor(myField, myValue) {

  //IE support

  if (document.selection) {

    myField.focus();

    sel = document.selection.createRange();

    sel.text = myValue;

  }

  //MOZILLA/NETSCAPE support

  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;

  }
  
  myField.focus();

}
function tempik(co) {insertAtCursor(document.fedit.z_novinka, co);}


// --------- print  ---------- //
function printMe() {
  window.print();
}

//********************* PLUGINS ****************************//
/**
 * Flash (http://jquery.lukelutman.com/plugins/flash)
* A jQuery plugin for embedding Flash movies.
 * 
 * Version 1.0
 * November 9th, 2006
 *
 * Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 * 
 * Inspired by:
 * SWFObject (http://blog.deconcept.com/swfobject/)
 * UFO (http://www.bobbyvandersluis.com/ufo/)
 * sIFR (http://www.mikeindustries.com/sifr/)
 * 
 * IMPORTANT: 
 * The packed version of jQuery breaks ActiveX control
 * activation in Internet Explorer. Use JSMin to minifiy
 * jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex).
 *
 **/ 
;(function(){
	
var $$;

/**
 * 
 * @desc Replace matching elements with a flash movie.
 * @author Luke Lutman
 * @version 1.0.1
 *
 * @name flash
 * @param Hash htmlOptions Options for the embed/object tag.
 * @param Hash pluginOptions Options for detecting/updating the Flash plugin (optional).
 * @param Function replace Custom block called for each matched element if flash is installed (optional).
 * @param Function update Custom block called for each matched if flash isn't installed (optional).
 * @type jQuery
 *
 * @cat plugins/flash
 * 
 * @example $('#hello').flash({ src: 'hello.swf' });
 * @desc Embed a Flash movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { version: 8 });
 * @desc Embed a Flash 8 movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { expressInstall: true });
 * @desc Embed a Flash movie using Express Install if flash isn't installed.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { update: false });
 * @desc Embed a Flash movie, don't show an update message if Flash isn't installed.
 *
**/
$$ = jQuery.fn.flash = function(htmlOptions, pluginOptions, replace, update) {
	
	// Set the default block.
	var block = replace || $$.replace;
	
	// Merge the default and passed plugin options.
	pluginOptions = $$.copy($$.pluginOptions, pluginOptions);
	
	// Detect Flash.
	if(!$$.hasFlash(pluginOptions.version)) {
		// Use Express Install (if specified and Flash plugin 6,0,65 or higher is installed).
		if(pluginOptions.expressInstall && $$.hasFlash(6,0,65)) {
			// Add the necessary flashvars (merged later).
			var expressInstallOptions = {
				flashvars: {  	
					MMredirectURL: location,
					MMplayerType: 'PlugIn',
					MMdoctitle: jQuery('title').text() 
				}					
			};
		// Ask the user to update (if specified).
		} else if (pluginOptions.update) {
			// Change the block to insert the update message instead of the flash movie.
			block = update || $$.update;
		// Fail
		} else {
			// The required version of flash isn't installed.
			// Express Install is turned off, or flash 6,0,65 isn't installed.
			// Update is turned off.
			// Return without doing anything.
			return this;
		}
	}
	
	// Merge the default, express install and passed html options.
	htmlOptions = $$.copy($$.htmlOptions, expressInstallOptions, htmlOptions);
	
	// Invoke $block (with a copy of the merged html options) for each element.
	return this.each(function(){
		block.call(this, $$.copy(htmlOptions));
	});
	
};
/**
 *
 * @name flash.copy
 * @desc Copy an arbitrary number of objects into a new object.
 * @type Object
 * 
 * @example $$.copy({ foo: 1 }, { bar: 2 });
 * @result { foo: 1, bar: 2 };
 *
**/
$$.copy = function() {
	var options = {}, flashvars = {};
	for(var i = 0; i < arguments.length; i++) {
		var arg = arguments[i];
		if(arg == undefined) continue;
		jQuery.extend(options, arg);
		// don't clobber one flash vars object with another
		// merge them instead
		if(arg.flashvars == undefined) continue;
		jQuery.extend(flashvars, arg.flashvars);
	}
	options.flashvars = flashvars;
	return options;
};
/*
 * @name flash.hasFlash
 * @desc Check if a specific version of the Flash plugin is installed
 * @type Boolean
 *
**/
$$.hasFlash = function() {
	// look for a flag in the query string to bypass flash detection
	if(/hasFlash\=true/.test(location)) return true;
	if(/hasFlash\=false/.test(location)) return false;
	var pv = $$.hasFlash.playerVersion().match(/\d+/g);
	var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
	for(var i = 0; i < 3; i++) {
		pv[i] = parseInt(pv[i] || 0);
		rv[i] = parseInt(rv[i] || 0);
		// player is less than required
		if(pv[i] < rv[i]) return false;
		// player is greater than required
		if(pv[i] > rv[i]) return true;
	}
	// major version, minor version and revision match exactly
	return true;
};
/**
 *
 * @name flash.hasFlash.playerVersion
 * @desc Get the version of the installed Flash plugin.
 * @type String
 *
**/
$$.hasFlash.playerVersion = function() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	} 
			catch(e) { return '6,0,0'; }				
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}		
	}
	return '0,0,0';
};
/**
 *
 * @name flash.htmlOptions
 * @desc The default set of options for the object or embed tag.
 *
**/
$$.htmlOptions = {
	height: 240,
	flashvars: {},
	pluginspage: 'http://www.adobe.com/go/getflashplayer',
	src: '#',
	type: 'application/x-shockwave-flash',
	width: 320,	
	wmode: 'transparent'
};
/**
 *
 * @name flash.pluginOptions
 * @desc The default set of options for checking/updating the flash Plugin.
 *
**/
$$.pluginOptions = {
	expressInstall: false,
	update: true,
	version: '6.0.65'
};
/**
 *
 * @name flash.replace
 * @desc The default method for replacing an element with a Flash movie.
 *
**/
$$.replace = function(htmlOptions) {
	this.innerHTML = '<div class="alt">'+this.innerHTML+'</div>';
	jQuery(this)
		.addClass('flash-replaced')
		.prepend($$.transform(htmlOptions));
};
/**
 *
 * @name flash.update
 * @desc The default method for replacing an element with an update message.
 *
**/
$$.update = function(htmlOptions) {
	var url = String(location).split('?');
	url.splice(1,0,'?hasFlash=true&');
	url = url.join('');
	var msg = '<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';
	this.innerHTML = '<span class="alt">'+this.innerHTML+'</span>';
	jQuery(this)
		.addClass('flash-update')
		.prepend(msg);
};
/**
 *
 * @desc Convert a hash of html options to a string of attributes, using Function.apply(). 
 * @example toAttributeString.apply(htmlOptions)
 * @result foo="bar" foo="bar"
 *
**/
function toAttributeString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'="'+this[key]+'" ';
	return s;		
};
/**
 *
 * @desc Convert a hash of flashvars to a url-encoded string, using Function.apply(). 
 * @example toFlashvarsString.apply(flashvarsObject)
 * @result foo=bar&foo=bar
 *
**/
function toFlashvarsString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'='+encodeURIComponent(this[key])+'&';
	return s.replace(/&$/, '');		
};
/**
 *
 * @name flash.transform
 * @desc Transform a set of html options into an embed tag.
 * @type String 
 *
 * @example $$.transform(htmlOptions)
 * @result <embed src="foo.swf" ... />
 *
 * Note: The embed tag is NOT standards-compliant, but it 
 * works in all current browsers. flash.transform can be
 * overwritten with a custom function to generate more 
 * standards-compliant markup.
 *
**/
$$.transform = function(htmlOptions) {
	htmlOptions.toString = toAttributeString;
	if(htmlOptions.flashvars) htmlOptions.flashvars.toString = toFlashvarsString;
	return '<embed ' + String(htmlOptions) + ' />';		
};

/**
 *
 * Flash Player 9 Fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
 *
**/
if (window.attachEvent) {
	window.attachEvent("onbeforeunload", function(){
		__flash_unloadHandler = function() {};
		__flash_savedUnloadHandler = function() {};
	});
}
	
})();

// --------- start of jQuery document.ready() ---------- //
  
$(document).ready(function() {

	// form remove help text
	/*$(".send_comment input").bind('click', function(){

    });*/
    
   //enter discussion anchor
   $('.enter_dis').click(function(){

        $(this).text('Loading...');
        temp = $(this).attr('id');
        elem = $(this).parents('.blogspot').find('.comments_window');
        if (elem.html() == '') {
          comments = $.ajax({type:"GET", async:false, url: "?spot_id="+temp}).responseText;
          elem.html(comments);
        }
        elem.slideToggle('fast');
        $(this).text('Enter discussion');
        return false;
    });
  
  //save a comment  
 $("form.send_comment button[type=submit]").live('click',
 function(){
   $(this).attr('disabled', 'disabled');
   $(this).text('Sending...');
   f_obsah = $(this).parents("form").find("textarea[name=c_obsah]").val();
   f_id = $(this).parents("form").find("input[name=c_spot_id]").val();
   f_autor = $(this).parents("form").find("input[name=c_autor]").val();
   co = $.ajax({type:"POST", async:false, url: "?", data: "f_obsah="+f_obsah+"&f_autor="+f_autor+"&f_id="+f_id}).responseText;
   
   if (co == 'false' || co == '') {
     alert('Error while sending. Please, try again.');
     }
   else {
     $(this).parents(".blogspot").find(".cont").append(co);
     $(this).parents("form").find("textarea[name=c_obsah]").val('');
     $(this).parents("form").find("input[name=c_autor]").val('');}
     
   $(this).text('Send');
   $(this).attr('disabled', '');
   
   return false;}
 );
    
   //delete comment
   $('.smaz_comment').live('click',function(){
   
   $(this).text('Deleting...');

        temp = $(this).attr('id');
        delet = $.ajax({type:"GET", async:false, url: "?smaz_cid="+temp}).responseText;

       if (delet != 'true') {
         alert('Error while deleting. Please, try again.');
         }
       else {
         $(this).parents(".cmtr").slideUp().remove();}
     
        return false;
   });
    
    
    
   
  //adding ID menu for compatibility
    $("menu").attr({id: "menu"});
    
  //submenu
  /*$('menu').after('<div class="pseudo"></div><ul class="character-list"><li><a href="/characters/">Alfonso Perplexon</a></li><li><a href="/characters/hill">Hill Persplexy</a></li><li><a href="/characters/paks">Paks Bilblox</a></li><li><a href="/characters/resuza">Resuza</a></li><li><a href="/characters/loxoc">General Loxoc</a></li><li><a href="/characters/judy">Judy Perplexon</a></li><li><a href="/characters/pappy">Louis "Pappy" Eubanks</a></li><li><a href="/characters/dusty">Dusty Magrewski</a></li><li><a href="/characters/purcheezie">Vice Admiral Purcheezie</a></li><li><a href="/characters/bambleweep">Dr. Van Bambleweep</a></li><li><a href="/characters/lars">Lars Sturluson</a></li><li><a href="/characters/spack">Spack</a></li><li><a href="/characters/kiril">Kiril</a></li><li><a href="/characters/nartam">Nartam</a></li></ul>');*/
  
  //switch button and footer design sign animations
    $("#header p > a").append("<em></em>");
      
    setTimeout(function(){$("#header p a span").fadeOut("slow");},100);
    $("#header p a").hover(function(){$(this).find("span").fadeIn("250")},function(){$(this).find("span").fadeOut("normal")});
    
  //adding special graphics to each first letter via. http://plugins.learningjquery.com/fancyletter/
    $.fn.fancyletter = function(options) {
  
      return this.each(function() {
        var $this = $(this);
        var opts = $.extend({}, $.fn.fancyletter.defaults, options || {}, $.metadata ? $this.metadata() : $.meta ? $this.data() : {});
        var node = this;
        while (node.childNodes.length) {
      	  node = node.firstChild;
        }
        var text = node.nodeValue;
        var firstLetter = text.slice(0,1);
        var re = new RegExp(opts.characters);
        if (re.test(firstLetter)) {
        	node.nodeValue = text.slice(1);
      	  var $span = $(['<span class="',
      	    opts.commonClass,
      	    ' ',
      	    opts.ltrClassPrefix,
            firstLetter.toLowerCase(),
            '">',
              firstLetter,
            '</span>']
      		.join('')
      		).prependTo(this);
          if (opts.bgImgPath !== null)
           $span.css('backgroundImage', 'url(' + opts.bgImgPath + firstLetter.toLowerCase() + opts.bgImgExt + ')');
          }
      });
    };  
  
    $.fn.fancyletter.defaults = {
      commonClass:      'fancy-letter', 
      ltrClassPrefix:   'ltr-',
      characters:       '[a-zA-Z]',
      bgImgPath:        null,
      bgImgExt:         null
    };
  
  //firing up the code just for P in content
  $('#content .inside .content > p').fancyletter();
  $('#content .inside .content > dl dt').fancyletter();
  $('.intro #content p').fancyletter();
  
  //cufon for fancy letters
  Cufon.replace('#content p span.fancy-letter');
  Cufon.replace('#content dl dt span.fancy-letter');
  Cufon.replace('.intro #content p span.fancy-letter');
  
  //night, home
  $('body.night.home #content p:contains("al book, Alfonso, his mother Judy")').css({paddingRight: '250px', textAlign: 'left'});
  $('body.night.home #content p:contains("in PDF format is a lost chapter from")').css({paddingRight: '210px', textAlign: 'left'});
  
  function stardust(){
  var mysrc = '/_data/lights.swf';
    
    $('body.night #header h1').after('<div id="lights"></div><div id="lights2"></div>');
    
    $('#lights').flash(
    { src: mysrc,
       width: 350,
       height: 90 }, 
    { update: false }
    );
    
    $('#lights2').flash(
    { src: mysrc,
       width: 350,
       height: 100 }, 
    { update: false }
    );
    
    }
    
    stardust();
    
    
    //$('body.change').append('<div class="fog"></div>');
    //$('body.night .fog').css({opacity: '0.8'});
      $('body.change .fog').animate ({
        opacity: 0
      }, 1000);
    setTimeout(function(){$("body.change .fog").css({display: 'none'});},1000);
    
    function sound(){
    var mysrc ='/_data/sound.swf';    
    
    $('#sound').flash(
    { src: mysrc,
       width: 1,
       height: 1 }, 
    { update: false }
    );
    }
    
    $('#header p a').hover(function() {$('#header h1').after('<div id="sound"></div>'); sound();}, function() {$('#sound').hide();}
    );
    
    //Fan Stuff
    $('body.fans form#mailing-list input:text').click(function() {
    $(this).attr({value: ""});
    });
    
    //Catacombs in Journey, night version
    $('body.night.journey.inside blockquote').append ('<a class="m1"></a><a class="m2"></a><a class="m3"></a><span class="m1">Here is the cellar where Alfonso and Bilblox enter the catacombs</span><span class="m2">Here is the waterfalls that Alfonso and Bilblox jump through and thus escape the catacombs</span><span class="m3">Here is the underground river that Alfonso and Bilblox navigate on their floating coffin.</span>');
    
    $('body.night.journey.inside blockquote a.m1').hover(function() {$('body.night.journey.inside blockquote span.m1').show();}, function(){$('body.night.journey.inside blockquote span.m1').hide();});
    $('body.night.journey.inside blockquote a.m2').hover(function() {$('body.night.journey.inside blockquote span.m2').show();}, function(){$('body.night.journey.inside blockquote span.m2').hide();});
    $('body.night.journey.inside blockquote a.m3').hover(function() {$('body.night.journey.inside blockquote span.m3').show();}, function(){$('body.night.journey.inside blockquote span.m3').hide();});


   //some intro stuff
   $('body.intro div.books blockquote').hover(
   function(){
     $(this).addClass('book-hover');},
   function(){
     $(this).removeClass('book-hover');}
   );
    
    
    //show title after mouse over
    $('body.somnos .somnos a[title], body.lighthouse .lighthouse a[title]').mouseover(function(e){
      $(this).after('<div id="somnos-title"></div>');
      var ttext = $(this).attr("title");
      $(this).attr({title:""});
      $('#somnos-title').text(ttext).show();
    });
    
    //hide title after mouse out    
    $('body.somnos .somnos a[title], body.lighthouse .lighthouse a[title]').mouseout(function(e){
      $(this).attr({title:$('#somnos-title').text()});
      $('#somnos-title').hide().remove();
    });    

   //point the magic button
   $('a.point-button').click(function(){
     $('body #main').append('<div class="pointer">Click the &ldquo;Magic Button&rdquo; and enter Hypnogogia!</div>');
   });
   
   //submenus
   $('menu .m2,.character-list').hover(
   function(){
     $('.character-list, .pseudo').css('visibility','visible')},
   function(){
     $('.character-list, .pseudo').css('visibility','hidden');
   })

    if ($('.blog-list').length) {
       $('menu .m6,.blog-list').hover(
       function(){
         $('.blog-list, .pseudo2').css('visibility','visible')},
       function(){
         $('.blog-list, .pseudo2').css('visibility','hidden');
       })
    }
   
   //play the music
    if ($('#header .mp3').length) {   
        $("#header .mp3").jmp3({
          showfilename: "false"
    	});
    }

	//working with login inputs  
  	$("#mailing-list input:text").click(function() {
	    $(this).attr({value: ""});
	});
	
	$('#header strong.mp3-holder').hover(
    function(){
    	$(this).addClass('mp3-hover')},
    function(){
    	$(this).removeClass('mp3-hover');
    });

	//intro tooltip
	$('body.intro blockquote.three a').click(function(){return false;});
	
	$('body.intro blockquote.three a').hover(
		function() {
			$(this).after('<div id="book-title"></div>');
		    var ttext = $(this).attr("title");
		    $(this).attr({title:""});
		    $('#book-title').text(ttext).show();
		},
		function() {
			$(this).attr({title:$('#book-title').text()});
	        $('#book-title').hide().remove();
		}
	);
	
		

});
// -------- end of jQuery document.ready() ---------- //

// --------- jQuery links animation --------- //
$(document).ready(function() {
  function filterPath(string) {
  return string
 .replace(/^\//,'')
 .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
 .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  $('a[href*=#][class!=no-scroll]').each(function() {
 var thisPath = filterPath(this.pathname) || locationPath;
 if (  locationPath == thisPath
 && (location.hostname == this.hostname || !this.hostname)
 && this.hash.replace(/#/,'') ) {
   var $target = $(this.hash), target = this.hash;
   if (target) {
  var targetOffset = $target.offset().top;
  $(this).click(function(event) {
    event.preventDefault();
    $('html, body').animate({scrollTop: targetOffset}, 400, function() {
   location.hash = target;
    });
  });
   }
 }
  });
});
// --------- end of jQuery links animation --------- //

//Cufon font initialization
  Cufon.replace('h2');
  Cufon.replace('h3');
