function resizeZoom() {
	zoom_width = 850;
	if (document.painting.width < zoom_width) {
	     zoom_width = document.painting.width + 28;
	}
    zoom_height = 650;
    if (document.painting.height < zoom_height) {
	    zoom_height = document.painting.height + 65;
	}

	window.resizeTo(zoom_width, zoom_height);
}

function newImage(arg) {
	if (document.images) {
		img = new Image();
		img.src = arg;
		return img;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		basket_w = newImage("images/ikona_kosik_w.gif");
		preloadFlag = true;
	}
}

function openTermsConditions() {
	return window.open('termsconditions.php', 'termsconditions', 
		'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=450px,height=400px');
}

function openRegisterTermsConditions() {
 return window.open('termsconditions.php?register', 'termsconditions', 
  'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=450px,height=400px');
}

function openZoom(zoom_url) {
	return window.open(zoom_url, 'zoom', 
  'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=450px,height=400px,top=10px,left=10px');
}
function openPohovka(zoom_url) {
	var pohovka=window.open(zoom_url, 'zoom', 
  'location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=690px,height=550px,top=50px,left=150px');
	if (window.focus) {pohovka.focus()}
	return false;

}


function lib_bwcheck() {
	this.ver = navigator.appVersion
	this.userAgent = navigator.userAgent.toLowerCase();
	this.dom = document.getElementById?1:0

	this.opera5 = (this.userAgent.indexOf('opera 5') != -1);
	this.opera = ((this.userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));

	this.saf    = ((this.userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
	this.webtv  = (this.userAgent.indexOf('webtv') != -1);

	this.ie = ((this.userAgent.indexOf('msie') != -1) && (!this.opera) && (!this.saf) && (!this.webtv));
	this.ie4	= ((this.ie) && (this.userAgent.indexOf('msie 4') != -1));
	this.ie5    = ((this.ie) && (this.userAgent.indexOf('msie 5') != -1));
	this.ie6    = ((this.ie) && (this.userAgent.indexOf('msie 6') != -1));
	this.ie7    = ((this.ie) && (this.userAgent.indexOf('msie 7') != -1));

	this.ps3    = (this.userAgent.indexOf('playstation 3') != -1);
	this.moz = ((navigator.product == 'Gecko') && (!this.saf));
	this.mac = (this.userAgent.indexOf("mac") != -1);
	this.kon = (this.userAgent.indexOf('konqueror') != -1);

	this.ns     = ((this.userAgent.indexOf('compatible') == -1) && (this.userAgent.indexOf('mozilla') != -1) && (!this.opera) && (!this.webtv) && (!this.saf));
	this.ns4 = ((this.ns) && (parseInt(this.ver) == 4));
	this.ns7 = ((this.ns) && (parseInt(this.ver) >= 5));
	// this.ns4 = (document.layers && !this.dom)?1:0;
	// this.ns6 = (this.dom && parseInt(this.ver) >= 5) ?1:0; 

	this.bw= (this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this;
}

var bw=new lib_bwcheck()


var speed = 30

var loop, timer

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}

function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

var scrolltextLoaded = false

function scrolltextInit () {
	oCont = new makeObj('divScrollTextContent')
	oScroll = new makeObj('divText','divScrollTextContent')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
}


function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

function fetch_tags(parentobj, tag)
{
	if (parentobj == null)
	{
		return new Array();
	}
	else if (typeof parentobj.getElementsByTagName != 'undefined')
	{
		return parentobj.getElementsByTagName(tag);
	}
	else if (parentobj.all && parentobj.all.tags)
	{
		return parentobj.all.tags(tag);
	}
	else
	{
		return new Array();
	}
}

function fetch_tag_count(parentobj, tag)
{
	return fetch_tags(parentobj, tag).length;
}


function p_AJAX_Handler(async)
{
	this.async = async ? true : false;
}

p_AJAX_Handler.prototype.init = function()
{
	if (typeof XMLHttpRequest != "undefined")
	{
		this.handler = new XMLHttpRequest();
		return (this.handler.setRequestHeader ? true : false);
	}
	else if (bw.ie && !bw.ie7)
	{
		this.handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
		return true;
	}
	else
	{
		return false;
	}
}

p_AJAX_Handler.prototype.is_compatible = function()
{
	if (bw.ie && !bw.ie4) { return true; }
	else if (typeof XMLHttpRequest != 'undefined')
	{
		try { return XMLHttpRequest.prototype.setRequestHeader ? true : false; }
		catch(e)
		{
			try { var tester = new XMLHttpRequest(); return tester.setRequestHeader ? true : false; }
			catch(e) { return false; }
		}
	}
	else { return false; }
}

p_AJAX_Handler.prototype.not_ready = function()
{
	return (this.handler.readyState && (this.handler.readyState < 4));
}

p_AJAX_Handler.prototype.onreadystatechange = function(event)
{
	if (!this.handler)
	{
		if  (!this.init())
		{
			return false;
		}
	}
	if (typeof event == 'function')
	{
		this.handler.onreadystatechange = event;
	}
	else
	{
		alert('XML Sender OnReadyState event is not a function');
	}

	return false;
}

p_AJAX_Handler.prototype.send = function(desturl, datastream)
{
	if (!this.handler)
	{
		if (!this.init())
		{
			return false;
		}
	}
	if (!this.not_ready())
	{
		this.handler.open('POST', desturl, this.async);
		this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.handler.send(datastream);
		if (!this.async && this.handler.readyState == 4 && this.handler.status == 200)
		{
			return true;
		}
	}
	return false;
}

p_AJAX_Handler.prototype.fetch_data = function(xml_node)
{
	if (xml_node && xml_node.firstChild && xml_node.firstChild.nodeValue)
	{
		return PHP.unescape_cdata(xml_node.firstChild.nodeValue);
	}
	else
	{
		return '';
	}
}

AJAX_Compatible = p_AJAX_Handler.prototype.is_compatible();

function ff_AJAX_RandomPaintingResolve_Init(objid)
{
	if (AJAX_Compatible)
	{
		var link_list = fetch_tags(fetch_object(objid), 'a');
		for (var i = 0; i < link_list.length; i++)
		{
			if (link_list[i].id && (link_list[i].id.substr(0, 16) == 'randompaintingup' || link_list[i].id.substr(0, 18) == 'randompaintingdown'))
			{
				link_list[i].onclick = random_painting_resolve;
			}
		}
	}
}


function ff_AJAX_RandomPaintingResolve(objid)
{
	this.objid = objid;
	this.xml_sender = null;
	this.direction = 'up';

	if (this.objid && this.objid.substr(0, 16) == 'randompaintingup')
	{
		this.direction = 'up';
	}

	if (this.objid && this.objid.substr(0, 18) == 'randompaintingdown')
	{
		this.direction = 'down';
	}

	var me = this;

	this.resolve = function()
	{
		this.xml_sender = new p_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('ajax.php', 'do=randompainting&direction=' + this.direction);
	}

	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200)
		{
			if (me.xml_sender.handler.responseText)
			{
				rpobj = fetch_object('randompainting');
				rpobj.innerHTML = me.xml_sender.handler.responseText;
			}
			if (bw.ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}
}


function random_painting_resolve(e)
{
	var resolver = new ff_AJAX_RandomPaintingResolve(this.id);
	resolver.resolve();
	return false;
}

