// Negativ JavaScript Document

var busy = false, timer, loadedImages = [], gallery, progress, bar;
var slide = 0;//tracks which slide is showing
var slidePause = 3000; //length of time to keep a slide at 1 opacity

function $E(A,B){
    return($(B)||document).getElement(A);
}

var currentProdId = 0;
var products = new Array();
var products_num = 0;

function nextProduct() {
	var p = products[currentProdId];
	if( p ) {
		var lastid = ( currentProdId == 0 ) ? products_num-1 : ( ( currentProdId == products_num ) ? 0 : ( currentProdId-1  ) );
		//alert(lastid);

		products[lastid].effect('opacity', {
			duration: 2000,
			onComplete: function(){
	    	}
	    }).start(0);

		$$('.product_rand_news').setStyle( 'z-index', 0 );
		p.setStyles({ 'opacity':0, 'display': 'block', 'z-index' : 1 });
		p.effect('opacity', {
			duration: 2000,
			onComplete: function(){
				currentProdId++;
				setTimeout( 'nextProduct()', 2000 );
	    	}
	    }).start(1);
	} else {
		currentProdId = 0;
		nextProduct();
	}
}


window.addEvent('domready', function() {
    $$('.product_rand_news').each(function(product) {
    	product.setStyles({ 'opacity': 0, 'display': 'none' });
    	products[products_num] = product;
    	products_num++;
    });
	nextProduct();
});

window.addEvent('domready', function() {

    if( $('sms1') ) {
        var sms1 = new Fx.Slide('sms1', {duration: 300});
        sms1.hide();
        $('m1').addEvent('click', function(){
            sms1.toggle()
        });
        /*
        $('sms1').addEvent('mouseout', function(){
            sms1.slideOut();
        });
        */
    }
/*
    var progress = $('progress'), bar = $E('#progress .bar'); 
    gallery = $('gallery');

    gallery.setStyles({'opacity': 0, 'display': 'none'});
    progress.setStyle('visibility', 'hidden');

    loadImages();
    function loadImages(){

        var galleryImgs = $$('#gallery img');
        if (galleryImgs.length > 0) galleryImgs.each(function(image) {	image.remove();	});

        progress.setStyle('visibility', 'visible');
        
        gallery.setStyle('display', 'block');
        new Asset.images(images, {
            onProgress: function(i) {
                this.setStyles({
                    'position': 'absolute',
                    'opacity': 0,
                    'left': (gallery.getCoordinates().width / 2) - (this.width / 2),
                    'top': (gallery.getCoordinates().height / 2) - (this.height / 2)
                });
                loadedImages[i] = this;
                var percent = ((i + 1) * progress.getStyle('width').toInt()) / images.length;
                //alert(percent);
                bar.setStyle('width', percent.toInt() ).setHTML(i + 1 + ' / ' + images.length);
            },
            onComplete: function() {
                var fx = $('gallery').effect('opacity').start(1).chain(function(){
                    progress.setStyle('display', 'none');
                    nextImg(-1);
                });
            } 
        });
    }
*/
});
/*
function nextImg(){
	slide = (slide == loadedImages.length-1)?0: slide+1;
	//slide = $random(0,loadedImages.length-1); //show pictures randomly
	if($E('img', gallery)){
		$E('img',gallery).effect('opacity', {duration: 1500, onComplete: function(){
			$E('img',gallery).remove();
			//showImg(loadedImages[slide]);// fade out completely before fading in next image
			}
		}).start(0);
		showImg(loadedImages[slide]);// fade out WHILE fading in next image
	}
	else
		showImg(loadedImages[slide]);
}
 
function showImg(img){
	img.inject(gallery);
	img.effect('opacity', {duration: 1500, onComplete: function(){
			setTimeout('nextImg()',slidePause);
		}
	}).start(1);
}
*/
function SelectDate(n) {
	hivas.mezo=n;
	w=window.open('inc/calendar/calendar.php?Datum='+n.value,'naptar','height=300,width=230,screenX=20,screenY=57,resizable=no,status=no,scrollbars=no,menubar=no,titlebar=no');
	w.focus();
}
function openWindow(theURL,winName,features) {
	if(!winName)
	    winName='_blank';
	if(!features)
		features = 'width=520, height=700, menubar=no, toolbar=no, location=no, status=no, scrollbars=yes, resizable=yes';
	window.open(theURL,winName,features);
}
function vi(id) {
    var o=document.getElementById(id);
	o.style.visibility='visible';
	o.style.display='block';
}
function hi(id) {
    var o=document.getElementById(id);
	o.style.visibility='hidden';
	o.style.display='none';
}
function elrejt(mit) {
    var mit=document.getElementById(mit);
	mit.style.display=(mit.style.display=="block")? "none" : "block";
}
function biztose(url, kerdes) {
	if (!kerdes)
		kerdes = "Biztos, hogy törölni akarja?";
    if (confirm(kerdes)) 
		location.href = url;
	return false;
}

function setCheckboxes(the_form, do_check) {
	var elts = document.forms[the_form].elements['foto_ids[]'];
	var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length : 0;
    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        }
    } else {
        elts.checked        = do_check;
    }
    return true;
}

function checkEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.value)) {
		return (true)
	}
	alert("Érvénytelen e-mail cím!\n     Írd be újra.")
	return (false)
}
function printwindow() {
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) { 
		window.print(); window.opener=self;
	}
}
function init(){
	var width = 180;
	var height = 180;
	self.resizeTo(width, height);
	self.moveTo((screen.width-width)/2, (screen.height-height)/2);
	self.focus();
}
function jumpMenu(selObj){
  eval("parent.location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function valueUpdate( val, InputId ) {
    if( val )
        document.getElementById(InputId).value = val;
}
