// (c) Albert Jindra Trebla

var topmenuoffest=0;
var thumbpage=0;
var thumbpages=0;
var thumheight=0;
var thlist;

var accordion;
var flipblocks=new Array();

var sirfwidthmax=424;

/*	
	Original:
	---------
	sIFR 2.0.2 (http://www.mikeindustries.com/sifr/)
	Copyright 2004 - 2006 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
	sIFR 2.0.2 is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
 
	Adapted:
	--------
	MoosIFR v0.4 rough mootools sIFR conversion
	Copyright 2007 Chris Martin (http://www.redantdesign.com/)
	MoosIFR v0.4 is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
 
	Description:
	------------
	Due to sIFR 2.0.2 having memory leaks I decided to roughly put together a mootools conversion.
	This release is incomplete and only performs the basic functionality of sIFR 2.0.2
	Please feel free to contribute to future releases and PLEASE keep memory leaks in mind.
 
*/
 
var MoosIFR = new Class({
	initialize: function(elements, options) {
		this.setOptions({
			flashsrc: "",
			textcolor: "#000000",
			linkcolor: null,
			hovercolor: null,
			bgcolor: "#FFFFFF",
			paddingtop: 0,
			paddingright: 0,
			paddingbottom: 0,
			paddingleft: 0,
			flashvars: "",
			wmode: "transparent"
		}, options);
 
		if(this.hasFlash() && $$(elements).length > 0) {
			if(this.options.wmode == "transparent"){
				this.options.bgcolor = "transparent";
			}
 
			//$$("html").addClass("sIFR-hasFlash");
 
			$$(elements).each(function(el){
				if(el.hasClass("sIFR-replaced") || el.hasClass("sIFR-alternate")) {
					return;
				}
				var offsets = el.getSize();
				var sWidth = offsets.size.x - this.options.paddingleft - this.options.paddingright;
				var sHeight = offsets.size.y - this.options.paddingtop - this.options.paddingbottom;
 
				/*
				cloning a node using the .clone() method to replace itself causes leaks,
				I chose to make the alternate content span node, then change links directly before flash replacement
				*/
				var alternate = new Element("span",{"class":"sIFR-alternate"}).setHTML(el.innerHTML);
				var links = "";
				$each(el.getElements("a"), function(link, index){ 
					links += "&sifr_url_" + index + "=" + link.getProperty("href");
					link.setProperty("href","asfunction:_root.launchURL," + index);
				});
				//end of link replacement
 
				//if you haven't sucked air through your teeth yet, the next lot of code will make you do so.
				this.flashvars = "txt=" + el.innerHTML.replace(/\+/g, "%2B").replace(/&/g, "%26").replace(/\"/g, "%22");
				if (sWidth>sirfwidthmax) sWidth=sirfwidthmax;
				this.flashvars += "&w=" + sWidth + "&h=" + (sHeight-5);
				this.flashvars += links + "&" + this.options.flashvars;
				$each(this.options, function(v, k){
					if(v && k != "flashvars"){
						this.flashvars += "&" + k + "=" + v;
					}
				}.bind(this));
 
				//change the content to flash stuff
				el.addClass("sIFR-replaced").setHTML(
					'<embed class="sIFR-flash" type="application/x-shockwave-flash" src="' + this.options.flashsrc + '" quality="best" wmode="' + this.options.wmode + '" bgcolor="' +  this.options.bgcolor + '" flashvars="' + this.flashvars + '" width="' + sWidth + '" height="' + sHeight + '" sifr="true"></embed>'
				);
 
				//add the alternate clone
				alternate.injectInside(el);
			}, this);
		}
 
	},
 
	//following function is a copy and paste
	hasFlash: function(){
		/*
		pulled from swfObject (http://blog.deconcept.com/swfobject/), 
		I didn't like the sIFR way of injecting vbscript to detect flash.
		*/
		var PlayerVersion = new flashVersion([0,0,0]);
 
		if(navigator.plugins && navigator.mimeTypes.length){
			var x = navigator.plugins["Shockwave Flash"];
			if(x && x.description) {
				PlayerVersion = new flashVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
			}
		} else {
			try{
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			}catch(e){
				try {
					var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					PlayerVersion = new flashVersion([6,0,21]);
					axo.AllowScriptAccess = "always";
				} catch(e) {
					if (PlayerVersion.major == 6) {
						return PlayerVersion;
					}
				}
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				} catch(e) {}
			}
			if (axo != null) {
				PlayerVersion = new flashVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}
		}
		return PlayerVersion.major >= 6;
	}
});
 
MoosIFR.implement(new Options);
 
/* also adapted from swfObject (http://blog.deconcept.com/swfobject/) */
var flashVersion = new Class({
	initialize: function(arrVersion){
		this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
		this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
		this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
	}
});

var imagesanim=$$('#slideshow img').length;

function fadeimg(inx,iny) {
oldimg=$$('#slideshow img')[inx];
newimg=$$('#slideshow img')[iny];
oldx=oldimg.src;
var marginChange = new Fx.Style(oldimg, 'opacity', {duration:300});
marginChange.start(1, 0).chain(function(){
$$('#slideshow img')[inx].src=newimg.src;
$$('#slideshow img')[iny].src=oldx;
var marginChange2 = new Fx.Style($$('#slideshow img')[inx], 'opacity', {duration:500});
marginChange2.start(0, 1);
});

}

function animbox() {

a=3;
b=imagesanim-a;
ia=(Math.floor(Math.random()*a));
ib=(Math.floor(Math.random()*b))+a;
fadeimg(ia,ib);
//console.log(ia+": "+b);


}



// --- action --------------------------------------
window.addEvent('domready', function(){

// printing
if ($('printer'))  { printin=$('printer');
printin.addEvent('click', function(){
window.print();
});}

// CRAETE  A IMAGES
imagesanim=18;//$$('#slideshow img').length;
basename="anim";

if (template=="1.2.3") { //privatni klientela
imagesanim=9;
basename="privat";
}

if (template=="1.3.1") { //pojisteni pro firmy
imagesanim=6;
basename="budova";
}


objss=$('slideshow');
objss.empty();
// <img src="/cmsms/uploads/respect-header/anim1.jpg" height="253" width="225" />
for(var i=1;i<=imagesanim;i++) {
box = new Element("img",{"width":"225","height":"253","src":"/uploads/respect-header/"+basename+i+".jpg"});
objss.adopt(box);
}



animbox();
var timer = animbox.periodical(5000);


new MoosIFR("h1", {
		flashsrc: "/sifr/verlag-book.swf", //verlag-light
		flashvars: "offsetTop=4",
		textcolor: "#236FB0",
		sCase:"upper"
	});
 




new MoosIFR(("#content h2"), {
		flashsrc: "/sifr/verlag-book.swf",
		 flashvars: "offsetTop=1",
		textcolor: "#236FB0"
	});



var list = $$('#mootoolmenu1 h3');
blockcount=0;
list.each(function(element) {


if (!(element.childNodes[0].tagName=="A")) {


 //if (!element.hasClass("active")) {
// console.log(element.hasClass="active");
	//var fx = new Fx.Styles(element, {duration:200, wait:false});
 var block  = element.getNext();
 
 
 
 
 var fx = new Fx.Slide(block);
 fx.hide();

flipblocks[blockcount]=fx;
 blockcount++;


 element.addClass('clicker');

/* 
element.addEvent('mouseenter', function(){
			
			element.addClass('clickerhover');
		});
*/ 
element.addEvent('click', function(){
			fx.toggle();
			if (element.hasClass('clickeropen')) element.removeClass('clickeropen'); else element.addClass('clickeropen');
		});

element.addEvent('mouseenter', function(){
			fx.slideIn();//toggle();
		//	if (element.hasClass('clickeropen')) element.removeClass('clickeropen'); else 
		element.addClass('clickeropen');
		}); 
		
		/*
		
block.addEvent('mouseleave', function(){
fx.slideOut();
		//element.removeClass('clickerhover');
					if (element.hasClass('clickeropen')) element.removeClass('clickeropen'); else element.addClass('clickeropen');
		});
 

 */

 
 
 }
	});
	
	
// fixed close all pops	
	
var topbigbox=$('menu_vert2');
topbigbox.addEvent('mouseleave', function(){

$$('#mootoolmenu1 h3').each(function(elb) {
elb.removeClass('clickeropen');
	});

flipblocks.each(function(elb) {
elb.slideOut();
 
		});
	//topmenuoffest=$('floatmenu').getTop()+$('contentbox').getTop()-$('menu_vert').getTop();
		});


topmenuoffest=$('floatmenu').getTop()+$('contentbox').getTop()-$('menu_vert').getTop();

$('floatmenu').style.top=topmenuoffest+"px";


new SmoothScroll({duration: 800});


window.addEvent('scroll', function(){ 

if ($('floatmenu').getSize().size.y < window.getSize().size.y ) {

y=Window.getScrollTop();
if (y<topmenuoffest) y=topmenuoffest;

$('floatmenu').setStyle('top', y+'px'); 

} else $('floatmenu').setStyle('top', topmenuoffest+'px'); 

});





// Safari menu bug

if (window.webkit) {

window.addEvent('domready', function(){

function correctmenu(){

topmenuoffest=$('floatmenu').getTop()+$('contentbox').getTop()-$('menu_vert').getTop();

$('floatmenu').style.top=topmenuoffest+"px";
//alert("saf fix "+topmenuoffest);
}

correctmenu.delay(500);

});

}



});



