/*

  SoundManager 2 Demo: Play MP3 links "in-place"
  ----------------------------------------------

  http://schillmania.com/projects/soundmanager2/

  A simple demo making MP3s playable "inline"
  and easily styled/customizable via CSS.

  Requires SoundManager 2 Javascript API.

*/
var autoplayme=false;// start playing the first sound right away
function InlinePlayer() {
  var self = this;
  var pl = this;
  var sm = soundManager; // soundManager instance
  this.excludeClass = 'inline-exclude'; // CSS class for ignoring MP3 links
  this.links = [];
  this.sounds = [];
  this.soundsByURL = [];
  this.indexByURL = [];
  this.lastSound = null;
  this.soundCount = 0;
  var isIE = (navigator.userAgent.match(/msie/i));

  this.config = {
    playNext: true // stop after one sound, or play through list until end
  }

  this.css = {
    // CSS class names appended to link during various states
    sDefault: 'sm2_link', // default state
    sLoading: 'sm2_loading',
    sPlaying: 'sm2_playing',
    sPaused: 'sm2_paused'
  }

  this.addEventHandler = function(o,evtName,evtHandler) {
    typeof(attachEvent)=='undefined'?o.addEventListener(evtName,evtHandler,false):o.attachEvent('on'+evtName,evtHandler);
  }

  this.removeEventHandler = function(o,evtName,evtHandler) {
    typeof(attachEvent)=='undefined'?o.removeEventListener(evtName,evtHandler,false):o.detachEvent('on'+evtName,evtHandler);
  }

  this.classContains = function(o,cStr) {
	return (typeof(o.className)!='undefined'?o.className.match(new RegExp('(\\s|^)'+cStr+'(\\s|$)')):false);
  }

  this.addClass = function(o,cStr) {
    if (!o || !cStr || self.classContains(o,cStr)) return false;
    o.className = (o.className?o.className+' ':'')+cStr;
  }

  this.removeClass = function(o,cStr) {
    if (!o || !cStr || !self.classContains(o,cStr)) return false;
    o.className = o.className.replace(new RegExp('( '+cStr+')|('+cStr+')','g'),'');
  }

  this.getSoundByURL = function(sURL) {
    return (typeof self.soundsByURL[sURL] != 'undefined'?self.soundsByURL[sURL]:null);
  }

  this.isChildOfNode = function(o,sNodeName) {
    if (!o || !o.parentNode) {
      return false;
    }
    sNodeName = sNodeName.toLowerCase();
    do {
      o = o.parentNode;
    } while (o && o.parentNode && o.nodeName.toLowerCase() != sNodeName);
    return (o.nodeName.toLowerCase() == sNodeName?o:null);
  }

  this.events = {

    // handlers for sound events as they're started/stopped/played

    play: function() {
      pl.removeClass(this._data.oLink,this._data.className);
      this._data.className = pl.css.sPlaying;
      pl.addClass(this._data.oLink,this._data.className);
    },

    stop: function() {
      pl.removeClass(this._data.oLink,this._data.className);
      this._data.className = '';
    },

    pause: function() {
      pl.removeClass(this._data.oLink,this._data.className);
      this._data.className = pl.css.sPaused;
      pl.addClass(this._data.oLink,this._data.className);
    },

    resume: function() {
      pl.removeClass(this._data.oLink,this._data.className);
      this._data.className = pl.css.sPlaying;
      pl.addClass(this._data.oLink,this._data.className);      
    },

    finish: function() {
      pl.removeClass(this._data.oLink,this._data.className);
      this._data.className = '';
      if (pl.config.playNext) {
        var nextLink = (pl.indexByURL[this._data.oLink.href]+1);
        if (nextLink<pl.links.length) {
          pl.handleClick({'target':pl.links[nextLink]});
        }
      }
    }

  }

  this.stopEvent = function(e) {
   if (typeof e != 'undefined' && typeof e.preventDefault != 'undefined') {
      e.preventDefault();
    } else if (typeof event != 'undefined' && typeof event.returnValue != 'undefined') {
      event.returnValue = false;
    }
    return false;
  }

  this.getTheDamnLink = (isIE)?function(e) {
    // I really didn't want to have to do this.
    return (e && e.target?e.target:window.event.srcElement);
  }:function(e) {
    return e.target;
  }

  this.handleClick = function(e) {
    // a sound link was clicked
    if (typeof e.button != 'undefined' && e.button>1) {
	  // ignore right-click
	  return true;
    }
    var o = self.getTheDamnLink(e);
    if (o.nodeName.toLowerCase() != 'a') {
      o = self.isChildOfNode(o,'a');
      if (!o) return true;
    }
    var sURL = o.getAttribute('href');
    if (!o.href || !o.href.match(/\.mp3(\\?.*)$/i) || self.classContains(o,self.excludeClass)) {
      if (isIE && o.onclick) {
        return false; // IE will run this handler before .onclick(), everyone else is cool?
      }
      return true; // pass-thru for non-MP3/non-links
    }
    sm._writeDebug('handleClick()');
    var soundURL = (o.href);
    var thisSound = self.getSoundByURL(soundURL);
    if (thisSound) {
      // already exists
      if (thisSound == self.lastSound) {
        // and was playing (or paused)
        thisSound.togglePause();
      } else {
        // different sound
        thisSound.togglePause(); // start playing current
        sm._writeDebug('sound different than last sound: '+self.lastSound.sID);
        if (self.lastSound) self.stopSound(self.lastSound);
      }
    } else {
      // create sound
      thisSound = sm.createSound({
       id:'inlineMP3Sound'+(self.soundCount++),
       url:soundURL,
       onplay:self.events.play,
       onstop:self.events.stop,
       onpause:self.events.pause,
       onresume:self.events.resume,
       onfinish:self.events.finish
      });
      // tack on some custom data
      thisSound._data = {
        oLink: o, // DOM node for reference within SM2 object event handlers
        className: self.css.sPlaying
      };
      self.soundsByURL[soundURL] = thisSound;
      self.sounds.push(thisSound);
      if (self.lastSound) self.stopSound(self.lastSound);
      thisSound.play();
      // stop last sound
    }

    self.lastSound = thisSound; // reference for next call

    if (typeof e != 'undefined' && typeof e.preventDefault != 'undefined') {
      e.preventDefault();
    } else {
      event.returnValue = false;
    }
    return false;
  }

  this.stopSound = function(oSound) {
    soundManager.stop(oSound.sID);
    soundManager.unload(oSound.sID);
  }

  this.init = function() {
    sm._writeDebug('inlinePlayer.init()');
    var oLinks = document.getElementsByTagName('a');
    // grab all links, look for .mp3
    var foundItems = 0;
    for (var i=0; i<oLinks.length; i++) {
      if (oLinks[i].href.match(/\.mp3/i) && !self.classContains(oLinks[i],self.excludeClass)) {
        self.addClass(oLinks[i],self.css.sDefault); // add default CSS decoration
        self.links[foundItems] = (oLinks[i]);
        self.indexByURL[oLinks[i].href] = foundItems; // hack for indexing
        foundItems++;
      }
    }
    if (foundItems>0) {
      self.addEventHandler(document,'click',self.handleClick);
	  if (autoplayme) {
	    self.handleClick({target:self.links[0],preventDefault:function(){}});
	  }
    }
    sm._writeDebug('inlinePlayer.init(): Found '+foundItems+' relevant items.');
  }

  this.init();

}

var inlinePlayer = null;

soundManager.onready(function() {
  if (soundManager.supported()) {
    // soundManager.createSound() etc. may now be called
    inlinePlayer = new InlinePlayer();
  }
});
function point_it(event,zoneid){
	clearInterval(ta);
	var IE = document.all?true:false;
	var tempX = 0;
	var tempY = 0;
	
	if (IE) { // grab the x-y pos.s if browser is IE
	tempX = event.clientX + document.documentElement.scrollLeft - document.getElementById("map").offsetLeft;
	tempY = event.clientY + document.documentElement.scrollTop - document.getElementById("map").offsetTop;
	oldx = document.getElementById("myicon1").style.left;
	oldy = document.getElementById("myicon1").style.top;
	

	}
	else {  // grab the x-y pos.s if browser is NS
	tempX = event.offsetX?(event.offsetX):event.pageX-document.getElementById("map").offsetLeft;
	tempY = event.offsetY?(event.offsetY):event.pageY-document.getElementById("map").offsetTop;
	oldx = document.getElementById("myicon1").style.left;
	oldy = document.getElementById("myicon1").style.top;
	}
	if (oldx==false) oldx='1';if (oldy==false) oldy='1';
	
	document.getElementById("cross").style.left = (tempX-6)+'px' ;
	document.getElementById("cross").style.top = (tempY-8)+'px' ;
	document.getElementById("cross").onclick = ajax_loadmap('map_inner','./projects/world/drawmap.php?zone='+zoneid+'&coords='+(tempX-6)+'-'+(tempY-8)+'&fromx='+oldx+'&fromy='+oldy,'<div class=mapload></div>');

}

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/****************************
*
*    move script by AXE
*
*
*////////////////////////////
var dirx = 1;
var diry = 1;
var spdx = 1;
var spdy = 1;
var imgLeftInt;
var imgTopInt;
var imgHeight;
var imgWidth;
var winWidth;
var winHeight;
var ta;
var stopx=0;
var stopy=0;
var brzina_x=0;
var brzina_y=0;
var i=1;
function animBall(tox,toy,divid) {
	if (i==1){
	imgLeftInt2 = parseInt(document.getElementById(divid).style.left);
    imgTopInt2 = parseInt(document.getElementById(divid).style.top);i++;
	
	koliko_desno=tox-imgLeftInt2;
	koliko_dolje=toy-imgTopInt2;
	
	if (koliko_desno<0) dirx = 0;
	if(koliko_dolje<0) diry = 0;
	
	if (Math.abs(koliko_desno)>Math.abs(koliko_dolje))//brzina_x veca od 1 a brzina_y je 1
		{brzina_x=Math.abs((koliko_desno/koliko_dolje)*2);brzina_y=2;}
	//          -100           100
	else if (Math.abs(koliko_desno<koliko_dolje))//brzina_y veca od 1 a brzina_x je 1
		{brzina_x=2;brzina_y=Math.abs((koliko_dolje/koliko_desno)*2);}
		
	else {brzina_x=2;brzina_y=2;}
	
	
	if (koliko_desno==0)//brzina_x veca od 1 a brzina_y je 1
		{brzina_x=0;brzina_y=2;}
	if (koliko_dolje==0)//brzina_x veca od 1 a brzina_y je 1
		{brzina_x=2;brzina_y=0;}
	
	
	
	}
    
    imgTopInt = parseInt(document.getElementById(divid).style.top);
    imgHeight =  parseInt(document.getElementById(divid).height);
    imgWidth =  parseInt(document.getElementById(divid).width);
    winWidth = parseInt(computeWin().windWidth);
    winHeight = parseInt(computeWin().windHeight);
	imgLeftInt = parseInt(document.getElementById(divid).style.left);

    if(dirx == 1){                            // if I should go right...
        goRight(tox,brzina_x,divid);
    } else {                                     // otherwise, I'd better go left!
        goLeft(tox,brzina_x,divid);
    }

    if(diry == 1) {                             // if I should go down...
        goDown(toy,brzina_y,divid);
    } else {                                              // otherwise, I'll go up!
        goUp(toy,brzina_y,divid);
    }
	
	if (stopx==1 && stopy==1){
		clearInterval(ta);i=1;//document.getElementById('debug').innerHTML='end';
		document.getElementById(divid).style.left=tox;
		document.getElementById(divid).style.top=toy;
		 stopx=0;
		 stopy=0;
		 brzina_x=0;
		 brzina_y=0;
		 dirx = 1;
		 diry = 1;
		spdx = 1;
		 spdy = 1;

		
		}
}

function goRight(toxr,vx,divid) {
	if (imgLeftInt<toxr){
    	document.getElementById(divid).style.left = imgLeftInt+vx +"px";
		}
	else
		stopx=1;
}
function goLeft(toxl,vx,divid) {
    if (imgLeftInt>toxl){
    	document.getElementById(divid).style.left = imgLeftInt-vx +"px";
		
		}
	else
		stopx=1; 
}

function goDown(toyd,vy,divid) {
	if (imgTopInt<toyd){
    	document.getElementById(divid).style.top = imgTopInt+vy +"px";
		
		}
	else
		stopy=1;
    
}

function goUp(toyu,vy,divid) {
	if (imgTopInt>toyu)//   10
    	document.getElementById(divid).style.top = imgTopInt-vy +"px";
	else
		stopy=1;
	
    
}

function setx(randnum2) {
    return randnum2;
}
function sety(randnum) {
    return randnum;
}

function computeWin(){
    if(document.body.clientWidth) {
        this.windWidth=document.body.clientWidth;
        this.windHeight=document.body.clientHeight;
    } else {
        this.windWidth = window.innerWidth;
        this.windHeight=document.innerHeight;
    }
return this;
}
function ajax_loadmap(divid,filename,noloading)
 {
	 	var a=document.getElementById(divid).innerHTML;
		 document.getElementById(divid).innerHTML=a+noloading;
		 jQuery(function($) {  $('#'+divid).load(filename);});
}
