window.defaultNum=4 //number of scenes in block related scene on Browse Scene page

function init() {
	
	setTimeout(function()
	{
		EventSelectors.start(rulesDefault);
		balloonTip.show();
		popUpWindow.init();
		try
		{
		Event.observe(window, 'resize', bodyHeight,false);
		}
		catch(e){
		//
		}
	},50);
	TopList.init();
	SceneList.init();
	FlashTabs.init();
	bodyHeight();
}

function initAfterAjax(ajax_id) {
	if (!ajax_id) return false;
	//balloonTip.hide();
	try
	{
		resizeTabs();
	}
	catch(e){
		//
	}
	correctPNG();
	return true;
}

function changeImageToFront()
{
	var front = $("front_img");
	var back = $("back_img");
	front.style.display = 'inline';
	back.style.display = 'none';
}
function changeImageToBack()
{
	var front = $("front_img");
	var back = $("back_img");
	front.style.display = 'none';
	back.style.display = 'inline';
}

// Event-Selectors
var rulesDefault = {
	// Show+Hide balloon-tooltip over the models
	'div.clearfix span#new_img1 a.balunsLink1:mouseover,tr.firstrow div.clearfix span.info a.balunsLink:mouseover,div.dvd_info div.clearfix div.info a.balunsLink:mouseover, table.scenes div.item div.si_prop a.balunsLink:mouseover, div#latest_updates div.clearfix div.info a.balunsLink:mouseover, div.ss_prop a.balunsLink:mouseover, div#windowStudios a.balunsLink:mouseover, div#featured a.balunsLink:mouseover, div#top8dvds .si_prop .balunsLink:mouseover, div#featured a.balunsLink1:mouseover, table#pcpc a.balunsLink1:mouseover, div#windowStudios div.info a.balunsLink1:mouseover, div.ss_prop a.balunsLink1:mouseover, #blockbrowseseries tr td div.bbs_div a.balunsLink:mouseover, div#noborder div.info a.balunsLink1:mouseover, div#browse_scene a.balunsLink:mouseover, div#latest_updates div.info a.balunsLink1:mouseover, div#bsiPlaceHolder div.info a.balunsLink:mouseover, div#browse_scene div#RelatedPhotoItemsViewId .item .balunsLink:mouseover, #bs_relate_movie td .balunsLink1:mouseover': function(element, event) {
		if(!element.tip){
			var tip = element.nextSibling;
			try{
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			}catch(e){
				tip = tip.nextSibling;
				if(tip.nodeName!="DIV")tip = tip.nextSibling;
				if(tip.nodeName!="DIV")tip = tip.nextSibling;
			}
			element.tip = tip;
		}
		window.eveVar = event;
		window.curEl = element;
		balloonTip.show(element.tip, {'x':5,'y':9}, 'simpleBalloon',event,true);
  },
	'div.clearfix span#new_img1 a.balunsLink1:mouseout,tr.firstrow div.clearfix span.info a.balunsLink:mouseout,div.dvd_info div.clearfix div.info a.balunsLink:mouseout, table.scenes div.item div.si_prop a.balunsLink:mouseout, div#latest_updates div.clearfix div.info a.balunsLink:mouseout, div.ss_prop a.balunsLink:mouseout, div#windowStudios a.balunsLink:mouseout, div#featured a.balunsLink:mouseout, div#top8dvds .si_prop .balunsLink:mouseout, div#featured a.balunsLink1:mouseout, table#pcpc a.balunsLink1:mouseout, div#windowStudios div.info a.balunsLink1:mouseout, div.ss_prop a.balunsLink1:mouseout, #blockbrowseseries tr td div.bbs_div a.balunsLink:mouseout, div#noborder div.info a.balunsLink1:mouseout, div#browse_scene a.balunsLink:mouseout, div#latest_updates div.info a.balunsLink1:mouseout, div#bsiPlaceHolder div.info a.balunsLink:mouseout, div#browse_scene div#RelatedPhotoItemsViewId .item .balunsLink:mouseout, #bs_relate_movie td .balunsLink1:mouseout': function(element) {
    balloonTip.hide();
	clearTimeout(window.popTime);
	},
/*	'div#featured a.balunsLink1:mouseover': function(element, event) {
		if(!element.tip){
			var tip = element.nextSibling;
			try{
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			if(tip.nodeName!="DIV")tip = tip.nextSibling;
			}catch(e){
				tip = tip.nextSibling;
				if(tip.nodeName!="DIV")tip = tip.nextSibling;
				if(tip.nodeName!="DIV")tip = tip.nextSibling;
			}
			element.tip = tip;
		}
		balloonTip.show(element.tip, {'x':10,'y':-80}, 'simpleBalloon',event);
  },
	'div#featured a.balunsLink1:mouseout': function(element) {
    balloonTip.hide();
	},*/
	'.dvd_info_buttons ul li a img:mouseover': function(element, event) {
		if(!element.tip){
			var tip = element.up().up().getElementsByTagName('div')[0];
			element.tip = tip;
		}
		balloonTip.show(element.tip, {'x':-19,'y':-40}, 'simpleBalloon',event,true);
  },
	'.dvd_info_buttons ul li a img:mouseout': function(element) {
    	balloonTip.hide();
	},
	'.dvd_info_buttons ul li a img:click': function(element) {
    	balloonTip.hide();
	}, 
// maybe a problem: Category and = in if statement
  	'#browsedvd div:click, small#topCatergory:click':function(element,event){
		var drag = $('side_category');
		var y = event.clientY+document.documentElement.scrollTop;
		var x = event.clientX+document.documentElement.scrollLeft;
		if(drag.style.display=="none"){
			drag.style.left = x+"px";
			drag.style.top = y+"px";	
			$('topCatergory').style.textDecoration="underline";
		}
		else{$('topCatergory').style.textDecoration="none";}
		fades('side_category');
	},
  	'#signin:mouseover':function(element,event){
		var drag = $('auth');
		var y = event.clientY+document.documentElement.scrollTop;
		var x = event.clientX+document.documentElement.scrollLeft;
		if(drag.style.display=="none"){
			drag.style.left = x-220+"px";
			drag.style.top = y+15+"px";	
		}
		fades('auth');
	}
}  
var flagLoaded=false;
Event.observe(window,'load',function(){
	flagLoaded=true;
	if($('faviritesBlock'))fades('faviritesBlock');
	});
function testDivs(){
	return true;
}

function fades(el)
{
	if (flagLoaded){
	if(typeof(el)=="string"){
		el = $(el);
	}
	var z = arguments[1]?arguments[1]:3;
	var set = arguments[2]?arguments[2]:false;
	window.zatuhanieNow = el;
		if(el.style.display=='none' || set=="show"){
			window.zatuhanieNow.style.display='block';
			//setTimeout("window.zatuhanieNow.style.display='block'",50);
			//Effect.BlindDown(el);
		}else{
			window.zatuhanieNow.style.display='none';
			//Effect.BlindUp(el);
		}
	}
}

Ajax.Responders.register({
  onComplete: function() { EventSelectors.assign(rulesDefault);}
})

function openImage(url,image_x,image_y)
{
    X_pos = (screen.width/2)-(image_x/2);
    Y_pos = (screen.height/2)-(image_y/2);
    window.open(url,'imagewin','scrollbars=no,resizable=no,left='+X_pos+',top='+Y_pos+',width='+image_x+',height='+image_y);
}

/* DOM-ready watcher by brothercake, http://www.brothercake.com/site/resources/scripts/domready/ */
function domFunction(f, a) {
	var n = 0;
	var t = setInterval(function() {
		var c = true;
		n++;
		if (typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
			c = false;
			if (typeof a == 'object') {
				for (var i in a) {
					if ((a[i] == 'id' && document.getElementById(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1) ) {
						c = true;
						break;
					}
				}
			}
			if (!c) { f(); clearInterval(t); }
		}
		if (n >= 60) {
			clearInterval(t);
		}
	}, 250);
};

/**
 * Add some html for decoring any element by css.
 *
 * elements (required) - elements in css style, like '#menu li'
 * layout - where add decor: 'top', 'bottom' or 'both' (by default)
 * wrap - add all childs to a wrap: true (by default) or false
 */
function AddDecor (elements, layout, wrap, id) {
	if (!elements) return false;
	var searchUnder = id ? '#'+id+' ' : '';
	switch (layout) {
		case 'top': this.layout = 'top'; break;
		case 'bottom': this.layout = 'bottom'; break;
		default: this.layout = 'both';
	}
	this.wrap = wrap == null ? true : (wrap == false ? false : true);

	var selArr = elements.split(',');
	var selNum = selArr.length;
	for (var j=0;j<selNum;j++) {
		var elArr = $$(searchUnder+selArr[j]);
		var elNum = elArr.length;
		for (var i=0;i<elNum;i++) {
			this.work(elArr[i]);
		}
	}
	return true;
}

AddDecor.prototype.work = function(el) {
	elChildsNum = el.childNodes.length;

	if (this.wrap) {
		var wrapObj = document.createElement('div');
		wrapObj.className = 'decorWrap';
		while(el.firstChild) wrapObj.appendChild(el.firstChild);
		el.appendChild(wrapObj);
	}

	if (this.layout == 'top' || this.layout == 'both') {
		var decorTop = document.createElement('b');
		decorTop.className = 'decorStr decorTop';
		var decorLeft = document.createElement('i');
		decorLeft.className = 'decorLeft';
		decorTop.appendChild(decorLeft);
		var decorCentre = document.createElement('i');
		decorCentre.className = 'decorCentre';
		decorTop.appendChild(decorCentre);
		var decorRight = document.createElement('i');
		decorRight.className = 'decorRight';
		decorTop.appendChild(decorRight);

		if (el.firstChild) {
			el.insertBefore(decorTop, el.firstChild);
		} else {
			el.appendChild(decorTop);
		}
	}

	if (this.layout == 'bottom' || this.layout == 'both') {
		var decorBottom = document.createElement('b');
		decorBottom.className = 'decorStr decorBottom';
		var decorLeft = document.createElement('i');
		decorLeft.className = 'decorLeft';
		decorBottom.appendChild(decorLeft);
		var decorCentre = document.createElement('i');
		decorCentre.className = 'decorCentre';
		decorBottom.appendChild(decorCentre);
		var decorRight = document.createElement('i');
		decorRight.className = 'decorRight';
		decorBottom.appendChild(decorRight);

		el.appendChild(decorBottom);
	}
}

/**
 * Select boxes replacer
 * by ZeT, http://zet.od.ua
 * version 0.5.2007-02-02
 *
 * based on http://www.easy-designs.net/articles/replaceSelect2/
 */
var Sbr = {
	init: function(id) {
		this.last = false;
		this.trigger = false;

		if (id && (form = document.getElementById(id))) {
			this.s = form.getElementsByTagName('select');
		} else {
			this.s = document.getElementsByTagName('select');
		}
    this.sCount = this.s.length;
		for (var i=0; i<this.sCount; i++) {
		  if (!this.s[i].multiple) {
  			if (!this.s[i].id) {
  				this.s[i].id = 'select_'+i;
  			}
  			this.run(this.s[i], i);
 			}
		}
	},

	run: function(obj, counter) {
		// building faux select structure
		var fauxSel = document.createElement('dl');
		fauxSel.className = obj.className ? obj.className + ' sbrWrap' : 'sbrWrap';
		obj.className = 'selReplaced';

		fauxSel.onclick = function() {	
			var selectElement = this.nextSibling;
			if (this.childNodes[1].className == 'sbrOptsCol') {
				selectElement.onfocus();
				Sbr.last.className = 'sbrOptsCol';
				Sbr.last = this.childNodes[1];
				Sbr.trigger = false;
				document.onclick = function() { if (Sbr.trigger) Sbr.last.className = 'sbrOptsCol'; Sbr.trigger = true; }
				this.childNodes[1].className = 'sbrOptsExp';
			} else {
				Sbr.lastObjId = false;
				document.onclick = function() {	}
				this.childNodes[1].className = 'sbrOptsCol';
			}
			if (this.childNodes[0].className == '') {
				this.nextSibling.focus();
			}
		}

		var curOpt = document.createElement('dt');
		curOpt.className = '';
		fauxSel.appendChild(curOpt);
		var optsWrap = document.createElement('dd');
		optsWrap.className = 'sbrOptsCol';
		fauxSel.appendChild(optsWrap);
		var optsList = document.createElement('ul');
		optsWrap.appendChild(optsList);
		optsList.style.zIndex = fauxSel.style.zIndex = 1000-counter;

		var opts = obj.options;
		var selectedOpt = (!obj.selectedIndex) ? 0 : obj.selectedIndex;
		for (var i=0; i<opts.length; i++) {
			var li = document.createElement('li');
			var txt = opts[i].text ? document.createTextNode(opts[i].text) : document.createTextNode('blank option');
			li.appendChild(txt);
			li.title = opts[i].title;
			li.selIndex = i;
			li.selectID = obj.id;
			li.onclick = function() {
				Sbr.selectMe(this);
			}
			if (i == selectedOpt) {
				li.className = 'sbrSelected';
				curOpt.appendChild(txt.cloneNode(false));
			}
			if (window.attachEvent) {
				li.onmouseover = function() {
					this.className += ' hover';
				}
				li.onmouseout = function() {
					this.className = this.className.replace(new RegExp(" hover\\b"), '');
				}
			}
			optsList.appendChild(li);
		}
		obj.oldonfocus = obj.onfocus;
		obj.onfocus = function() {
			if (this.oldonfocus) this.oldonfocus();
			this.previousSibling.childNodes[0].className = 'sbrFocused';
		}
		obj.oldonblur = obj.onblur;
		obj.onblur = function() {
			if (this.oldonblur) this.oldonblur();
			this.previousSibling.childNodes[0].className = '';
		}
		obj.oldonchange = obj.onchange;
		obj.onchange = function() {
			if(obj.previous == undefined) {
				obj.previous = obj.value;
			} else {
				if(obj.previous == obj.value) {
					return;
				} else {
					obj.previous = obj.value;
				}
			}
			//alert("Change");
			if (this.oldonchange) this.oldonchange();
			var idx = this.selectedIndex;
			var ul = this.previousSibling.childNodes[1].childNodes[0];
			Sbr.selectMe(ul.childNodes[idx],1);
		}
		obj.onkeypress = obj.onchange;

		obj.parentNode.insertBefore(fauxSel,obj);
	},

	selectMe: function(liObj) {
		var selectElement = liObj.parentNode.parentNode.parentNode.nextSibling;
		var lis = liObj.parentNode.getElementsByTagName('li');
		for (var i=0; i<lis.length; i++) {
			if (lis[i] != liObj) {
				lis[i].className = '';
				lis[i].onclick = function() {
					Sbr.selectMe(this);
				}
			} else {
				this.setVal(liObj.selectID, liObj.selIndex);
				liObj.className = 'sbrSelected';
				var curOpt = liObj.parentNode.parentNode.parentNode.childNodes[0];
				curOpt.removeChild(curOpt.childNodes[0]);
				curOpt.appendChild(liObj.childNodes[0].cloneNode(false));
				if(arguments[1] != 1){
					selectElement.onchange();
				}
			}
		}
	},

	setVal: function(objID, val) {
		var obj = document.getElementById(objID);
		obj.selectedIndex = val;
	}
}


var balloonTip = {
	show: function(source, offset, balloonClass,event,delayed) {
		if (!this.balloon) this.build();
		this.balloon.style.display = 'none';
		if (!source) return false;
		if (typeof(source) == 'object' && source.tagName != null) {
			this.source = source.cloneNode(true);
			this.source.style.display = '';
		} else {
			this.source = document.createTextNode(source);
		}
		this.offset = offset ? (typeof(offset)!='object' ? {'x':offset,'y':offset} : offset ) : {'x':0,'y':0};
		this.balloon.className = balloonClass ? balloonClass : '';

		this.tip.appendChild(this.source);
		this.sizes = {
			scrollX : (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft),
			scrollY : (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop),
			winX : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth),
			winY : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)
		};
		balloonTip.posit(event);
		document.onmousemove = function(event) {balloonTip.posit(event);}
		//this.balloon.style.display = 'block';
		if(delayed) window.popTime = setTimeout(function(){ fades(this.balloon,2.5,"show");}.bind(this), 1500);
	},

	build: function() {
		this.balloon = document.createElement('div');
		this.balloon.setAttribute('id','balloon');
		this.balloon.style.display = 'none';
		this.tip = document.createElement('div');
		this.tip.setAttribute('id','balloon-tip');
		this.balloon.appendChild(this.tip);
		document.getElementsByTagName('body').item(0).appendChild(this.balloon);
	},

	posit: function(evt) {
		//this.balloon.style.left = 'auto';
		var bX = this.balloon.offsetWidth;
		var bY = this.balloon.offsetHeight;
		var mx = this.mouseX(evt);
		var my = this.mouseY(evt);
		if(mx<0 || my<0){
			return;
		}
		var x = mx + this.offset.x;
		var y = my + this.offset.y;

		if (bX < this.sizes.winX && x - this.sizes.scrollX + bX >= this.sizes.winX) {
			x -= bX + this.offset.x * 2;
		}
		if (bY < this.sizes.winY && y - this.sizes.scrollY + bY >= this.sizes.winY) {
			y -= bY + this.offset.y * 2;
		}

		this.balloon.style.left = x + 'px';
		this.balloon.style.top = y + 'px';
	},

	hide: function() {
		document.onmousemove = function() { return false; }
		try{this.tip.removeChild(this.source);}catch(e){
			//
		}
		this.source = null;
		this.balloon.style.display = 'none';
		this.balloon.style.left = this.balloon.style.top = '-1000px';

	},

	mouseX: function(evt) {
		if (document.all) if (event) evt = event;
		if (evt.pageX)
			return evt.pageX;
		if (evt.clientX)
			return evt.clientX + this.sizes.scrollX;
		return -1;
	},
	mouseY: function(evt) {
		if (document.all) if (event) evt = event;
		if (evt.pageY)
			return evt.pageY;
		if (evt.clientY)
			return evt.clientY + this.sizes.scrollY;
		return -1;
	}
}

/* hides 'splash' div and sets cookie 'cms_splash_screen' about it */
function hideSplash() {
	expires = 365; // days

	var today = new Date();
	today.setTime( today.getTime() );
	var expires_date = new Date( today.getTime() + (expires * 1000 * 60 * 60 * 24) );
	document.cookie = 'cms_splash_screen=1' + ';expires=' + expires_date.toGMTString();

	$('splash_out').style.display = 'none';
	$('splash').style.display = 'none';

}
/**
*@package EnvisioNext javascript library
*@subpackage Popup static window
*@copyright (C) 2007 EnvisioNext.com  <support@EnvisioNext.com>
*@author Anton Zavidov <anton.zavidov@envisionext.com.ua>
*/

//Base class
var popUpWindow = {
	// Init popuphandler
	// This function must be run after load document
	init : function()
	{
		var popups = $$(".tooltip");
		for(var i=0; i<popups.length; i++){
			var activePopUpElement = this.find(popups[i],"prev");
			if(activePopUpElement)
			{
				Event.observe(activePopUpElement,'click',this.open);
			}
		}
	},
	// Find handler object
	find : function(element,mode)
	{
		var prev = true;
		clas = (mode == "prev")? "popup" : "tooltip";
		while(element.className != clas && prev == true) {
			if((mode == "prev" && element.previousSibling) || (mode != "prev" && element.nextSibling)){
				element = (mode == "prev")? element.previousSibling : element.nextSibling;
			} else {
				prev = false;
				return false;
			}
		}
		return element;
	},
	// Open/Close popup window
	open : function()
	{
		element = (navigator.appName == "Microsoft Internet Explorer")?Event.element(event):this;
		var popUp = popUpWindow.find(element, "next");
		if(popUp)
		{
			if(popUp.style.display == "" || popUp.style.display == "none")
			{
				popUp.style.display = "block";
			} else {
				popUp.style.display = "none";
			}
		}
	},
	// Close popup window if clicked 'close'
	closePopUp : function(element)
	{
		element.parentNode.parentNode.style.display = "none";
	}
}

/**
*@package EnvisioNext javascript library
*@subpackage Toplist
*@copyright (C) 2007 EnvisioNext.com  <support@EnvisioNext.com>
*@author Anton Zavidov <anton.zavidov@envisionext.com.ua>
*/
var TopList = {
	globalDivClass : "list",
	linkClass : "name",
	coverImg : "coverImg",
	coverLink : "coverLink",
	urls1 : false,
	imgs : false,
	init : function()
	{
		var element = $$("div."+TopList.globalDivClass+" a."+TopList.linkClass);
		this.urls1 = $$("." + TopList.coverLink);
		this.imgs = $$("." + TopList.coverImg);
		
		for (var i=0; i<element.length; i++) {
			Event.observe(element[i], 'mouseover', this.mouseOver.bindAsEventListener(this));
		}
	},
	mouseOver : function(event)
	{
		var element = Event.element(event);
		if(element.tagName!="A"){
			element = element.parentNode;
		}
		this.urls1[0].href = element.href;
		var div = element.nextSibling;
		if(!div)div = element.parentNode.nextSibling;
			try{
				this.imgs[0].src = div.childNodes[0].src;
			} catch(e){
				var div = element.parentNode.parentNode.nextSibling;
				try{
					this.imgs[0].src = div.childNodes[0].src;
				} catch(e){}
			}
	}
}

var SceneList = {
	globalDivClass : "list_scen",
	linkClass : "name_scen",
	coverImg : "coverImg_scen",
	coverLink : "coverLink_scen",
	urls1 : false,
	imgs : false,
	init : function()
	{
		var element = $$("div."+SceneList.globalDivClass+" a."+SceneList.linkClass);
		this.urls1 = $$("." + SceneList.coverLink);
		this.imgs = $$("." + SceneList.coverImg);
		
		for (var i=0; i<element.length; i++) {
			Event.observe(element[i], 'mouseover', this.mouseOver.bindAsEventListener(this));
		}
	},
	mouseOver : function(event)
	{
		var element = Event.element(event);
		if(element.tagName!="A"){
			element = element.parentNode;
		}
		this.urls1[0].href = element.href;
		var div = element.nextSibling;
		if(!div)div = element.parentNode.nextSibling;
			try{
				this.imgs[0].src = div.childNodes[0].src;
			} catch(e){
				var div = element.parentNode.parentNode.nextSibling;
				try{
					this.imgs[0].src = div.childNodes[0].src;
				} catch(e){}
			}
	}
}

// Debug Window
var dbw = function(element)
{
	var d="";
	for(f in element) {
		try
		{
			d+=f+"="+element(f)+"\n";
		} 
		catch(e)
		{
			continue;
		}
	}
	myW = open("", "displayWindow", "status=no,toolbar=no,menubar=yes");
	myW.document.open();
	myW.document.write("<html><body><textarea style='width: 500px; heigth: 500px'>"+d+"</textarea></body></html>");
	myW.document.close();
	
}
/**
*@package EnvisioNext javascript library
*@subpackage ListUp
*@copyright (C) 2007 EnvisioNext.com  <support@EnvisioNext.com>
*@author Anton Zavidov <anton.zavidov@envisionext.com.ua>
*/
var ListUp = {
	init : function()
	{
		if($('RelatedItemsViewIdDriver') && $('RelatedItemsViewId') && $('RelatedItemsViewIdSelect')){
			Event.observe($('RelatedItemsViewIdDriver'), 'click', this.RelatedItemsViewIdDriver.bindAsEventListener(this));
			//Event.observe($('RelatedItemsViewIdSelect'), 'change', this.RelatedItemsViewIdSelect.bindAsEventListener(this));
			this.selects($('RelatedItemsViewIdSelect'),'RelatedItemsView');
			this.hiddenEl('RelatedItemsViewId','RelatedItemsView');
			$('RelatedItemsViewId').style.display = "block";
		}
		if($('RelatedPhotoItemsViewIdDriver') && $('RelatedPhotoItemsViewId') && $('RelatedPhotoItemsViewIdSelect')){
			Event.observe($('RelatedPhotoItemsViewIdDriver'), 'click', ListUp.RelatedPhotoItemsViewIdDriver.bindAsEventListener(ListUp));
			//Event.observe($('RelatedPhotoItemsViewIdSelect'), 'change', this.RelatedPhotoItemsViewIdSelect.bindAsEventListener(this));
			this.selects($('RelatedPhotoItemsViewIdSelect'),'RelatedPhotoItemsView');
			this.hiddenEl('RelatedPhotoItemsViewId','RelatedPhotoItemsView');
			$('RelatedPhotoItemsViewId').display = "block";
		}
	},
	RelatedItemsViewIdDriver : function()
	{
		var el = $('RelatedItemsViewId');
		this.hiddenEl('RelatedItemsViewId','RelatedItemsView');
		if(el.style.display == "" || el.style.display == "block") {
			el.style.display = "none";
			$('RelatedItemsViewIdDriver').className = $('RelatedItemsViewIdDriver').className.split(" ")[0]+" collapse";
			
		} else {
			el.style.display = "block";
			$('RelatedItemsViewIdDriver').className = $('RelatedItemsViewIdDriver').className.split(" ")[0]+" expand";
		}
	},
	RelatedPhotoItemsViewIdDriver : function()
	{
		var el = $('RelatedPhotoItemsViewId');
		this.hiddenEl('RelatedPhotoItemsViewId','RelatedPhotoItemsView');
		if(el.style.display == "" || el.style.display == "block") {
			el.style.display = "none";
			$('RelatedPhotoItemsViewIdDriver').className = $('RelatedPhotoItemsViewIdDriver').className.split(" ")[0]+" collapse";
		} else {
			el.style.display = "block";
			$('RelatedPhotoItemsViewIdDriver').className = $('RelatedPhotoItemsViewIdDriver').className.split(" ")[0]+" expand";
		}
	},
	RelatedItemsViewIdSelect : function(el)
	{
		var value = el.value;
		setSettings('RelatedItemsView',value);
		this.hiddenEl('RelatedItemsViewId','RelatedItemsView');
	},
	RelatedPhotoItemsViewIdSelect : function(el)
	{
		var value = el.value;
		setSettings('RelatedPhotoItemsView',value);
		this.hiddenEl('RelatedPhotoItemsViewId','RelatedPhotoItemsView');
	},
	hiddenEl : function(el,cook)
	{		
		var num = getSettings(cook);
		if(num!=null){
			num = parseInt(num);
		} else {
			num=window.defaultNum;
			setSettings(cook,num);
		}
		var elements = $$("#"+el+" div.item");
		for(var i=0; i<elements.length; i++){
			if(i>=num) {
				elements[i].style.display="none";
			} else {
				elements[i].style.display="block";
			}
		}
	},
	selects : function(se,cook)
	{
		var num = getSettings(cook);
		if(num!=null){
			num = parseInt(num);
		} else {
			num = (!num)?window.defaultNum:num;
			setSettings('RelatedPhotoItemsView',num);
		}
		for(var i=0; i<se.options.length; i++){
			if(parseInt(se.options[i].value) == parseInt(num)){
				se.options[i].selected = true;
				return;
			}
		}
	}
}
/**
*@package EnvisioNext javascript library
*@subpackage Cookies
*@copyright (C) 2007 EnvisioNext.com  <support@EnvisioNext.com>
*@author Anton Zavidov <anton.zavidov@envisionext.com.ua>
*/
var setSettings = function(name, value)
{
	document.cookie = name + "=" + escape(value) +
      	"; expires=Mon, 01-Jan-2017 00:00:00 GMT" +
      	"; path=/";
}
var getSettings = function(name)
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
   	var offset = 0;
    var end = 0;
    if (cookie.length > 0)
	{
		offset = cookie.indexOf(search);
		if (offset != -1)
		{
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1)
			{
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
/**
*@package EnvisioNext javascript library
*@subpackage Flash Tabs
*@copyright (C) 2007 EnvisioNext.com  <support@EnvisioNext.com>
*@author Anton Zavidov <anton.zavidov@envisionext.com.ua>
*/
var FlashTabs = {
	formats : {
		// Example
		//"dvd":[x,y,mode,flvFolder,flvName,providerName];
		"dvd":[648,478,0,"tour_movies/","640.flv"],
		"high":[488,372,1,"tour_movies/","480.flv"],
		"medium":[328,265,2,"tour_movies/","320.flv"],
		"low":[192,144,3,"tour_movies/"]
	},
	init : function()
	{
		var lis = $$('div.download_dvd_flash li');
		for (var i=0; i<lis.length; i++) {
			Event.observe(lis[i], 'click', this.click.bindAsEventListener(this));
		}
		var active = $$('div.download_dvd_flash li.active');
		if(active[0]){
			var clas = active[0].id;
			var format = this.formats[clas];
			if(!format){
				return;
			}
			var div = $("free_tour_player");
			div.style.width = format[0] + "px";
			div.style.height = format[1] + "px";
			this.correctHeight(format[1], div);
			flashStart(format[5],format[3],format[4]);
		}
	},
	click : function(event)
	{
		var element = Event.element(event);
		var clas = element.id;
		if(!clas) {
			return;
		}
		var format = this.formats[clas];
		if(!format){
			return;
		}
		var active = $$('div.download_dvd_flash li.active');
		if(active[0]){
			active[0].className = ""; 
		}
		element.className = "active";
		var div = $("free_tour_player");
		div.style.width = format[0] + "px";
		div.style.height = format[1] + "px";
		this.correctHeight(format[1], div);
		en_flash_sendToPlayer(format[2],format[5],format[3],format[4]);
	},
	correctHeight : function(height,div)
	{
		var cover = $$('div.download_dvd_flash div.main_flash');
		if(!cover){
			return
		} else cover = cover[0];
		div.style.paddingTop = parseInt((485-height)/2)+"px";
	}
}
////
var bodyHeight = function() { 
	var body = $$('body')[0];
	body.style.height = 'auto';
	var winHeight = (document.documentElement.clientHeight?document.documentElement.clientHeight :	document.body.clientHeight);
	body.style.height = body.offsetHeight > winHeight ? 'auto' : '100%'; 
};

