function submitOver(id){
// 	document.getElementById(id).style.backgroundColor='#89B4DA';
// 	document.getElementById(id).style.borderColor='#4A8CC6';
}
function submitOut(id){
// 	document.getElementById(id).style.backgroundColor='#4A8CC6';
// 	document.getElementById(id).style.borderColor='#30699C';
}

var imgLayoutDir = 'images/';

function imgOver(id, img, imgDir){
	imgDir = (imgDir == undefined) ? imgLayoutDir : imgDir;
	document.getElementById(id).src = imgDir + img;
}

function imgOut(id, img, imgDir){
	imgDir = (imgDir == undefined) ? imgLayoutDir : imgDir;
	document.getElementById(id).src = imgDir + img;
}

function preloadImages(arrImagesOut, arrImagesOver, imgDir){
	imgDir = (imgDir == undefined) ? 'images/' : imgDir;
	
	arrImgOut = new Array();
	for ( i=0;i<arrImagesOut.length;i++ ){
		arrImgOut[i] = new Image();
		arrImgOut[i].src = imgDir + arrImagesOut[i];
	}
	
	if ( arrImagesOver != undefined ){
		arrImgOver = new Array();
		for ( i=0;i<arrImagesOver.length;i++ ){
			arrImgOver[i] = new Image();
			arrImgOver[i].src = imgDir + arrImagesOver[i];
		}
	}
}

function inputLabels (container) {
	var children = container.childNodes;
	var i;
	for (i=0; i < children.length; i++) {
		if (children.item(i).tagName == 'LABEL') {
			children.item(i).setAttribute('id',children.item(i).htmlFor + 'Label');
			children.item(i).onfocus = function() {
				focusInput(this.htmlFor);
			};
			children.item(i).onblur = function() {
				blurInput(this.htmlFor);
			};
		} else if ( children.item(i).tagName == 'INPUT') {
			if (children.item(i).getAttribute('type') == 'text') {
                blurInput(children.item(i).getAttribute('id')); // inicjalizacja początkowa
				children.item(i).onfocus = function() {
					focusInput(this.getAttribute('id'));
				};
				children.item(i).onblur = function() {
					blurInput(this.getAttribute('id'));
				};
			}
		} else if ( children.item(i).tagName == 'TEXTAREA') {
                blurInput(children.item(i).getAttribute('id')); // inicjalizacja początkowa
				children.item(i).onfocus = function() {
					focusInput(this.getAttribute('id'));
				};
				children.item(i).onblur = function() {
					blurInput(this.getAttribute('id'));
				};
		} else if ( children.item(i).tagName == 'DIV') {
			inputLabels (children.item(i));
		}
	}
	
}

function blurInput(id) {
	var elem = document.getElementById ( id );
	if (elem.value == '') {
		document.getElementById(id + "Label").style.display = 'block';
	} else {
		document.getElementById(id + "Label").style.display = 'none';
	}
}
function focusInput(id) {
	document.getElementById(id + "Label").style.display = 'none';
}

function scrollLeft() {
    var totalWidth = $('producersBox').getScrollSize().x;
    var visibleWidth = $('producersBox').getSize().x;
    var left = parseInt($$('#producersBox > pre').getStyle('left'));

    if (left < 0) {
        $$('#producersBox > pre').setStyle('left', left + 3);
    }
}

function scrollRight() {
    var totalWidth = $('producersBox').getScrollSize().x;
    var visibleWidth = $('producersBox').getSize().x;
    var left = parseInt($$('#producersBox > pre').getStyle('left'));

    // Chrome i IE6 trochę inaczej to liczą
    if (Browser.Engine.webkit == true || (Browser.Engine.trident == true && Browser.Engine.version < 5)) {
        if (visibleWidth - totalWidth < left) {
            $$('#producersBox > pre').setStyle('left', left - 3);
        }
    } else {
        if (totalWidth > visibleWidth) {
            $$('#producersBox > pre').setStyle('left', left - 3);
        }
    }
}

function rememberPosition(position)
{
    myCookie = Cookie.write('productScrollPosition', position);
}

function recallPosition()
{
    var totalWidth = $('producersBox').getScrollSize().x;
    var visibleWidth = $('producersBox').getSize().x;
    var scrollPosition = Cookie.read('productScrollPosition');

    if (scrollPosition < 0) {
        if (visibleWidth - totalWidth <= scrollPosition) {
            $$('#producersBox > pre').setStyle('left', scrollPosition + 'px');
        } else {
            $$('#producersBox > pre').setStyle('left', (visibleWidth - totalWidth) + 'px');
        }
    }
}

function initScroll() {
    var timeToRepeat = 15;
    var sc;
    recallPosition();

    $('leftButton').addEvent('click', function()
    {
        return false;
    });

    $('leftButton').addEvent('mousedown', function()
    {
        scrollLeft();
        sc = scrollLeft.periodical(timeToRepeat);
        return false;
    });

    $('leftButton').addEvent('mouseup', function()
    {
        if (sc) {
            $clear(sc);
            rememberPosition(parseInt($$('#producersBox > pre').getStyle('left')));
        }
        return false;
    });

    $('leftButton').addEvent('mouseout', function()
    {
        if (sc) {
            $clear(sc);
            rememberPosition(parseInt($$('#producersBox > pre').getStyle('left')));
        }
        return false;
    });

    $('rightButton').addEvent('click', function()
    {
        return false;
    });

    $('rightButton').addEvent('mousedown', function()
    {
        scrollRight();
        sc = scrollRight.periodical(timeToRepeat);
        return false;
    });

    $('rightButton').addEvent('mouseup', function()
    {
        if (sc) {
            $clear(sc);
            rememberPosition(parseInt($$('#producersBox > pre').getStyle('left')));
        }
        return false;
    });

    $('rightButton').addEvent('mouseout', function()
    {
        if (sc) {
            $clear(sc);
            rememberPosition(parseInt($$('#producersBox > pre').getStyle('left')));
        }
        return false;
    });
}

/* used by search engine */

function eraseDefaultLabel(obj)
{
    if (queryEntered == false && obj.value == "wpisz szukane słowo") {
        obj.value = "";
    }
}

function checkForQuery(obj)
{
    if (obj.value == "") {
        queryEntered = false;
        obj.value = "wpisz szukane słowo";
    } else {
        queryEntered = true;
    }
}
