/*** JOICO - 2011 - JS by Polgar Peter (Force) ***/

// header search
function headerSearchInit () {

	var inputID = $('input#header_search_input');
	var inputNewVal = 'keresés...';

	if ( $(inputID).val() == '' || $(inputID).val() == inputNewVal ) {
		$(inputID).val(inputNewVal);
	}
	inputID.bind('focus', function () {
		if ( $(this).val() == inputNewVal ) {
			$(this).val('');
		}
	}).bind('blur', function () {
		if ( $(this).val() == '' ) {
			$(this).val(inputNewVal);
		}
	});

};

// menu things
function menuInit () {

	$('ul#header_menu li ul li:last-child a').addClass('last');

};

// nivoslider
function nivoSliderInit () {

	$('div#header_billboard').nivoSlider({
		effect: 'boxRain', // Specify sets like: 'fold,fade,sliceDown'
		slices: 15, // For slice animations
		boxCols: 8, // For box animations
		boxRows: 4, // For box animations
		animSpeed: 500, // Slide transition speed
		pauseTime: 3000, // How long each slide will show
		startSlide: 0, // Set starting Slide (0 index)
		directionNav: false, // Next & Prev navigation
		directionNavHide: false, // Only show on hover
		controlNav: true, // 1,2,3... navigation
		controlNavThumbs: false, // Use thumbnails for Control Nav
		controlNavThumbsFromRel: false, // Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', // Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
		keyboardNav: true, // Use left & right arrows
		pauseOnHover: true, // Stop animation while hovering
		manualAdvance: false, // Force manual transitions
		captionOpacity: 0.8, // Universal caption opacity
		prevText: 'Prev', // Prev directionNav text
		nextText: 'Next' // Next directionNav text
	});

};

// ie zindex bugfix
function ieZindexFixInit () {

   var zIndexNumber = 10000;
   // Put your target element(s) in the selector below!
   $('*').each(function() {
	   $(this).css('zIndex', zIndexNumber);
	   zIndexNumber -= 10;
   });

};

// ie facebook box bugfix
function ieFacebookFixInit () {

	$('iframe#social_facebook').attr('allowTransparency', 'true');

};

// fancybox
function fancyboxInit () {

	// gallery
	$("a[rel=gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			if ( currentArray.length <= 1 ) {
				return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			} else {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		}
	});

	// videos
	$("a[rel=video]").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		    : 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'		    : 'transparent',
			'style'        : 'zIndex, 10000',
			'allowfullscreen'	: 'true'
			}
		});
		return false;
	});

};

// pager
function pagerInit () {

	$('div.textBox ul.pager').each(function () {
		var ulWidth = $(this).width();
		var parentWidth = $(this).parent().width();
		var setMargin = (parentWidth-ulWidth)/2;
		$(this).css('marginLeft', setMargin);
	});

	$('div.textBox ul.pager li.active a').click(function () {
		return false;
	});

};

// product list
function productListInit () {

	$('div.product_list ul li a span').each(function () {
		if ( $(this).height() > 43 ) {
			$(this).addClass('line2');
		}
	});

};

$(document).ready(function() {
//-----

// header search
headerSearchInit ();

// menu things
menuInit ();

// nivoslider
nivoSliderInit ();

// ie bugz
if ($.browser.msie && jQuery.browser.version < 8) {
	// ie zindex bugfix
	ieZindexFixInit ();
};
if ($.browser.msie && jQuery.browser.version < 9) {
	// ie facebook box bugfix
	ieFacebookFixInit ();
};

// fancybox
fancyboxInit ();

// pager
pagerInit ();

// product list
productListInit ();

//-----
});

