News.maxCount = 3;
News.setContent = function () {
        var item;
        var news = jQ(this.xmlData).find('/short_news_page/xml_news');
        var count = news.length;

        if (count > 0) {
            var toAppend = '';
            
            if (count < this.maxCount) {
                this.maxCount = count;
            }
            for(var i = 0; i < this.maxCount; i++){
                var item = news[i];
                var img = jQ(item).find('obrazek');
                toAppend += '<li>';
                toAppend += '<img alt="' + jQ(item).find('title').text() + '" src="' + 
                    img.attr('src') + '" width="' + img.width + '" height="' + img.height + '" />';
                toAppend += '<strong>'+ jQ(item).find('date').text() + '</strong>';
                toAppend += '<span> | </span>';
                if( typeof jQ(item).find('link').attr('href') != 'undefined' && jQ(item).find('link').attr('href') != '') {
                    toAppend += '<a href="' + jQ(item).find('link').attr('href') + '">' + jQ(item).find('title').text() + '</a>';
                } else {
                    toAppend += jQ(item).find('title').text();
                }                
                toAppend += '<p>' + jQ(item).find('perex').text() + '</p>';
                toAppend += '</li>';
            }
            jQ("#news").append(toAppend);
        }
        return true;
}

function questionCheck(formname, action) {
    var ctrl = document.forms[formname];
    if (ctrl) ctrl.action = action;
    return FormControl(ctrl,fc_quest);
}
function clearContent(id) {
    var x = document.getElementById(id);
    if (x) {
        if (x.value) {
            if ( (x.value.substring(0,1)=='\u00A0') || (x.value.substring(0,1) == ' ')) {
                x.value = '';
            }
        }
    }
}
var selectedObj=null;
var offsetX,offsetY;


function dragDiv(event) {
    if(window.event) event=window.event;
    if(selectedObj) {
	if(document.all) {
            selectedObj.pixelLeft=event.clientX - offsetX;
            selectedObj.pixelTop=event.clientY - offsetY;
        } else {
            selectedObj.left=event.clientX - offsetX;
            selectedObj.top=event.clientY - offsetY;
        }
        return false;
    }
}

function releaseDiv() {
    if (selectedObj) {
        selectedObj.zIndex=10000;
        selectedObj=null;
    }
}
function engageDiv(id,event) {
    if(document.getElementById) {
        var obj=document.getElementById(id);
        if(obj.style) {
            selectedObj=obj.style;
            selectedObj.zIndex=2;
            if(document.all) {
                offsetX=event.clientX-selectedObj.pixelLeft;
                offsetY=event.clientY-selectedObj.pixelTop;
            } else {
                offsetX=event.clientX-parseInt(selectedObj.left,10);
                offsetY=event.clientY-parseInt(selectedObj.top,10);
            }
            return false;
        }
    }
}

function closeDiv(id) {
    if(document.getElementById) {
        var obj=document.getElementById(id);
        if(obj.style) {
            selectedObj=obj.style;
            selectedObj.display = "none";
            selectedObj=null;
            return false;
        }
    } else if(document.layers) {
        document.layers[id].visibility = "hide";
        return false;
    }
}

document.onmousemove=dragDiv;
document.onmouseup=releaseDiv;




    
jQ(document).ready(function() {
    
    // Ovladani banneru na uvodni strance
    switchBanners();
    
    // Ovlada roztaznost produktovych boxu
    openBox();
    
    // workaround pro IE7 aby zobrazil absolutne pozicovany div (ktery je v kodu vedle floatovaneho prvku, v teto kombinaci abs.pozic.prvek zmizi)
    jQ(".product_hp").addClass("ie");
});

/**
 * Nastaveni ID elementu pro bannery v hlavicce
 */
var elSwitch = '#swithBanners';
var elBanners = '#promoImages';
var switchBannersTimeout;

/**
 * Ovladani banneru na uvodni strance
 */
function switchBanners() {
    window.setTimeout("runSwitchBanners()", 5000);
    jQ(elBanners).children('div:eq(0)').show();
    
    jQ(elSwitch).children().click(function() {
        if (jQ(this).hasClass('active') == false) {
            runSwitchBanners(jQ(this));
            window.clearTimeout(switchBannersTimeout);
        }
    });
}

function runSwitchBanners(oClickedEl) {
    //pokud je kliknuto - nebere se nasledujici mozny, ale aktualni - proto activeBanner.text() * 1 - 1
    var clickedNumber = (typeof oClickedEl == 'undefined') ? false : true;
    var activeBanner = (!clickedNumber) ? jQ(elSwitch).children('.active') : oClickedEl;
    var activePos = (!clickedNumber) ? (activeBanner.text() * 1) : (activeBanner.text() * 1 - 1);
    var countBanners = jQ(elSwitch).children('*').length;

    var buttonIndex = countBanners - activePos - 1;

    buttonIndex = (buttonIndex == -1 ) ? (countBanners - 1) : buttonIndex;

    
    jQ(elSwitch).children().removeClass('active');
    jQ(elBanners).children('div:visible').fadeOut(1000);
    
    var divIndex = activePos * 1 ;
    divIndex = (divIndex == countBanners) ? 0 : divIndex;
    
    jQ(elSwitch).children().eq(buttonIndex).addClass('active');
    jQ(elBanners).children('div').eq(divIndex).fadeIn(1000);
    
    if(!clickedNumber) {
        switchBannersTimeout = window.setTimeout("runSwitchBanners()", 5000);
    }
}

function openBox(){

/*
    jQ(".product_hp").hover(function(){
        jQ(this).stop(true, true).addClass("hover");
    },
    function(){
        jQ(this).stop(true, true).removeClass("hover");
    }    
    );
*/



jQ(".product_hp").hover(function(){

    jQ(this).children(".content").css( "height", "auto" );
    var productHP = jQ(this).children(".content").height();
    jQ(this).children(".content").css( "height", "255px" );
    
    jQ(this).children(".content").stop(true, true).animate({
           height: productHP
        },200);
    },
    function(){
        jQ(this).children(".content").stop(true, true).animate({
            height: '255px'
        },200);
    }    
    );

}
