/**
 * Simple DOM shorthands
 */


function element(tag, attributes, children, properties)
{
        var element = document.createElement(tag);
        if(attributes) for(var i in attributes) element.setAttribute(i, attributes[i]);
        if(properties) for(var i in properties) element[i] = properties[i];
        if(children) for(var i = 0; i < children.length; i++) element.appendChild(children[i]);
        return element;
}

function div(attributes, children, properties)
{
        return element('div', attributes, children, properties);
}

function a(attributes, children, properties)
{
        return element('a',   attributes, children, properties);
}

function img(attributes, children, properties)
{
        return element('img', attributes, children, properties);
}

function object(attributes, children, properties)
{
        return element('object', attributes, children, properties);
}

function param(attributes, children, properties)
{
        return element('param', attributes, children, properties);
}


var flashbox;

function hide()
{
        flashbox.style.display = 'none';
        flashbox.innerHTML = '';
        return false;
}


/**
 * Methods to work with flashbox
 */

function initFlashBox()
{

//        var flashbox, image, caption, flash, movie, anchor;

/*
        function show(e)
        {alert(this);
                image.src = this.href;
                anchor.style.width = this.getAttribute('width');
                flash.setAttribute('width', this.getAttribute('flashwidth'));
                flash.setAttribute('height', this.getAttribute('flashheight'));
                flash.style.marginTop = this.getAttribute('top');
                flash.style.marginLeft = this.getAttribute('left');
                flash.setAttribute('data', this.getAttribute('movie'));
                movie.setAttribute('value', this.getAttribute('movie'));
                try {caption.removeChild(caption.firstChild);}
                catch(e) {}
        try{
                if(this.getAttribute('alt')) caption.appendChild(document.createTextNode(this.getAttribute('alt')));
        }
        catch(ex)
        {
        alert(ex);
        }
                flashbox.style.display = 'block';
                return false;
        }
*/

        function show()
        {
                style = "margin-top: " + this.getAttribute('top') + "px; margin-left: " + this.getAttribute('left') + "px;";
                flashbox.innerHTML = '<a href="#" title=".:: Kliknutím okno zavřete ::." onclick="return hide(this);"><div id="flashboxAnchor">' +
                                     '<img src="/_clip/close.jpg" border="0" id="closeButton" />' +
                                     '<object id="flashboxMovie" style="' + style + '" type="application/x-shockwave-flash" data="' + this.getAttribute('movie') + '" width="' + this.getAttribute('flashwidth') + '" height="' + this.getAttribute('flashheight') + '">' +
                                     '<param name="movie" value="' + this.getAttribute('movie') + '" />' +
                                     '<param name="quality" value="high" />' +
                                     (this.getAttribute('wmode') ? '<param name="wmode" value="' + this.getAttribute('wmode') + '" />' : '') +
                                     '</object>' +
                                     '<img id="flashboxImage" border="0" src="' + this.href + '"/>' +
                                     '</div></a>' +
                                     '<div id="flashboxDetails"><div id="flashboxCaption"></div></div>';
                flashbox.style.display = 'block';
                with(document.getElementById('flashboxMovie'))
                {
                        style.marginLeft = this.getAttribute('left') + 'px';
                        style.marginTop = this.getAttribute('top') + 'px';
                }
                document.getElementById('flashboxAnchor').style.width = this.getAttribute('width') + 'px';
                return false;
        }


        try
        {

                var as = document.getElementsByTagName("a");
                for(var i = 0; i < as.length; i++) with(as[i]) {
                        if(getAttribute('href') && getAttribute('rel') == 'flashbox')
                                as[i].onclick = show;
                }


                // the rest of this code inserts html at the end of the page that looks like this:
                //
                // <div id="overlay">
                //              <a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
                //      </div>
                // <div id="flashbox">
                //              <a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
                //                      <img id="closeButton" />
                //                      <img id="flashboxImage" />
                //                      <object type="application/x-shockwave-flash" data="" width="x" height="y" title="title">
                //                          <param name="movie" value="url" />
                //                          <param name="quality" value="high" />
                //                      </object>
                //              </a>
                //              <div id="flashboxDetails">
                //                      <div id="flashboxCaption"></div>
                //                      <div id="keyboardMsg"></div>
                //              </div>
                // </div>
/*                document.body.appendChild(
                        flashbox = div(
                                {'id': 'flashbox'},
                                [
                                        a(
                                                {
                                                        'href' :'#',
                                                        'title':'.:: Kliknutím okno zavřete ::.'
                                                },
                                                [
                                                anchor = div({'id':'flashboxAnchor'},
                                                [
                                                        img({'id': 'closeButton', 'border': '0', 'src': 'close.gif'}, [], {'src':'close.gif'}),
                                                        flash = object(
                                                                {
                                                                        'id': 'flashboxMovie',
                                                                        'type': "application/x-shockwave-flash"
                                                                },
                                                                [
                                                                        movie = param({'name':'movie'}),
                                                                        param({
                                                                                'name': 'quality',
                                                                                'value': 'high'
                                                                        })
                                                                ]
                                                        ),
                                                        image = img({'id': 'flashboxImage','border':'0'})
                                                ]
                                                )
                                                ],
                                                {onclick: hide}
                                        ),
                                        div(
                                                {'id': 'flashboxDetails'},
                                                [
                                                        caption = div({'id': 'flashboxCaption'})
                                                        //, div({'id': 'keyboardMsg'})
                                                ]
                                        )
                                ]
                        )
                );*/

                document.body.appendChild(
                        flashbox = document.createElement('div')
                ).setAttribute('id', 'flashbox');



        }
        catch(e)
        {
                // alert(e);
        }

}



try      {window.addEventListener('load', initFlashBox, true);}
catch(e) {
        try      {window.attachEvent('onload', initFlashBox);}
        catch(e) {window.onload = initFlashBox;}
}

// open new window
function newWin(URL) {
	okno=window.open(URL,'blank');
	okno.focus();
	return false;

}

// insert flash
function flash(file,width,height,flashvars,winmode,id,classs,alternative) {

	var shockmode = false;
	if(id!=''){
		id=' id="'+id+'"';
	}
	if(classs!=''){
		classs=' class="'+classs+'"';
	}
	var mimetype = 'application/x-shockwave-flash';

	if (navigator.mimeTypes) {
		if (navigator.mimeTypes[mimetype] != null) {
			if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
				shockmode = true;
		      }
		}
	}
	if (!shockmode && navigator.appVersion.indexOf('MSIE') !=-1) {
		shockmode = true;
	}
	if (shockmode) {
		document.write('<object'+id+' type="application/x-shockwave-flash" data="'+file+'"'+classs+' width="'+width+'" height="'+height+'">');
		document.write('<param name="movie" value="'+file+'" />');
		document.write('<param name="menu" value="false" />');
		document.write('<param name="wmode" value="'+winmode+'" />');
		if(flashvars!=''){
			document.write('<param name="flashvars" value="'+flashvars+'" />');
		}
		document.write(alternative);
		document.write('</object>');
	}
	else {
		document.write(alternative);
	}
}


