/*** Haver vagy! - Index page - 2012 - JS by Polgar Peter (Force) ***/

// JQuery noconflict
var JQ = jQuery.noConflict();

// preload
/*function preloadInit() {

	$.preload([
		"../img/backgrounds/background1.jpg",
		"../img/backgrounds/background2.jpg",
		"../img/backgrounds/background3.jpg",
		"../img/backgrounds/background4.jpg",
		"../img/backgrounds/background5.jpg",
		"../img/backgrounds/background6.jpg"
    ]);

};*/

// infiled label
function infieldLabelInit() {

	// use the title attribute of form item
	JQ('.infieldLabel').each(function() {
		var basicVal = JQ(this).attr('title');
		JQ(this).val(basicVal);
		JQ(this).focus(function() {
			if ( JQ(this).val() == basicVal ) {
				JQ(this).val('');
			}
		});
		JQ(this).blur(function() {
			if ( JQ(this).val() == '' ) {
				JQ(this).val(basicVal);
			}
		});
	});

};

// popup
function popupInit() {

	fileUploadInit();

	// open videos
	JQ('div#videos .popupOpen').bind('click', function() {
		JQ('div#popupLayer, div#popupBox').fadeIn(300);

		// get values
		var videoTitle = JQ(this).find('span.title').html();
		var videoDate = JQ(this).find('span.date').html();
		var videoURL = JQ(this).attr('href');
		//alert(videoTitle+', '+videoDate+'; '+videoURL);

		// set content
		JQ('div#popupBox div#content').html('<h2>'+videoTitle+'</h2><p>'+videoDate+'</p><object width="560" height="340"><param name="movie" value="'+videoURL+'&amp;&amp;color1=0x234900&amp;color2=0x4e9e00&autoplay=1" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" /><embed src="'+videoURL+'&amp;&amp;color1=0x234900&amp;color2=0x4e9e00&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340" wmode="transparent"></embed></object>');

		return false;
	});

	// open registration
	var regForm = JQ('div#regForm').html();
	JQ('a#btn_reg').bind('click', function() {
		JQ('div#popupLayer, div#popupBox').fadeIn(300);

		// set content
		JQ('div#popupBox div#content').html(regForm);
		JQ('div#regForm div.inner').html('');

		return false;
	});
		JQ('a#reg_close').live('click', function() {
			JQ('a.popupClose').trigger('click');
			return false;
		});

	// open forgot pass
	var forgotPassForm = JQ('div#forgotPassForm').html();
	JQ('a#forgotpass').bind('click', function() {
		JQ('div#popupLayer, div#popupBox').fadeIn(300);

		// set content
		JQ('div#popupBox div#content').html(forgotPassForm);
		JQ('div#forgotPassForm div.inner').html('');

		return false;
	});
		JQ('a#forgotpass_close').live('click', function() {
			JQ('a.popupClose').trigger('click');
			return false;
		});

	// close
	JQ('.popupClose, div#popupLayer').bind('click', function() {
		JQ('div#popupLayer, div#popupBox').fadeOut(300, function() {
			JQ('div#popupBox div#content').html('');
			JQ('div#regForm div.inner').html(regForm);
			JQ('div#forgotPassForm div.inner').html(forgotPassForm);
		});
		return false;
	});

};

/* Adatvédelmi nyilatkozat */

function showAgreementForm() {
	JQ('#popup_inner #content #regformInner').hide();
	JQ('#popup_inner #content #agreementForm').show();
	JQ('#popupBox a.popupClose').hide();
	JQ('#popupBox a.popupAgreementClose').show();
	JQ('#popupBox a.popupAgreementClose').click(function(event) {
		JQ('#popup_inner #content #regformInner').show();
		JQ('#popup_inner #content #agreementForm').hide();
		JQ('#popupBox a.popupClose').show();
		JQ('#popupBox a.popupAgreementClose').hide();		
	});
}

// set height
function setHeightInit() {

	var bodyHeight = JQ(window).height();
	//alert(bodyHeight);
	JQ('div.background').height(bodyHeight);

};

// footer background
function footerBGInit (outFadeTime, outLoopTime) {

	// set basic backgrounds
	/*for ( var i = 0; i < 7; i++) {
		var bgLink = 'img/backgrounds/background'+i+'.jpg';
		JQ('div#img'+i).css('backgroundImage', 'url('+bgLink+')');
	}*/

	// fade in / fade out boxes
	for ( var a = 0; a < 100; a++ ) {
		if ( a == 0 ) {
			setTimeout(function() {
				JQ('div#img1').fadeOut(outFadeTime);
			}, outLoopTime*1);
			setTimeout(function() {
				JQ('div#img2').fadeOut(outFadeTime);
			}, outLoopTime*2);
			setTimeout(function() {
				JQ('div#img3').fadeOut(outFadeTime);
			}, outLoopTime*3);
			setTimeout(function() {
				JQ('div#img4').fadeOut(outFadeTime);
			}, outLoopTime*4);
			setTimeout(function() {
				JQ('div#img5').fadeOut(outFadeTime);
			}, outLoopTime*5);
			setTimeout(function() {
				JQ('div#img1').fadeIn(outFadeTime, function() {
					JQ('div#img2, div#img3, div#img4, div#img5').fadeIn(0);
				});
			}, outLoopTime*6);
		} else {
			setTimeout(function() {
				JQ('div#img1').fadeOut(outFadeTime);
			}, outLoopTime*1+outLoopTime*7*a);
			setTimeout(function() {
				JQ('div#img2').fadeOut(outFadeTime);
			}, outLoopTime*2+outLoopTime*7*a);
			setTimeout(function() {
				JQ('div#img3').fadeOut(outFadeTime);
			}, outLoopTime*3+outLoopTime*7*a);
			setTimeout(function() {
				JQ('div#img4').fadeOut(outFadeTime);
			}, outLoopTime*4+outLoopTime*7*a);
			setTimeout(function() {
				JQ('div#img5').fadeOut(outFadeTime);
			}, outLoopTime*5+outLoopTime*7*a);
			setTimeout(function() {
				JQ('div#img1').fadeIn(outFadeTime, function() {
					JQ('div#img2, div#img3, div#img4, div#img5').fadeIn(0);
				});
			}, outLoopTime*6+outLoopTime*7*a);
		}
	}

};

// file upload skin
function fileUploadInit() {

  JQ("input.file").filestyle({ 
	  image: "img/grid/button_tallozas.gif",
	  imageheight : 30,
	  imagewidth : 87,
	  width : 210
  });

};

JQ(document).ready(function() {
//-----

// preload
//preloadInit();

// infiled label
infieldLabelInit();

// popup
popupInit();

// set height
setHeightInit();

// footer background
footerBGInit (500, 8000);

// resize actions
JQ(window).resize(function() {
	setHeightInit ();
});

// file upload skin
fileUploadInit();

//-----
});

