jQuery(document).ready(function(){
	//jQuery('body').prepend('<div id="loader" />');
	try {
		Cufon.replace('h2, h3, .content h4, h5', { fontFamily: 'arial' });
		//Cufon.replace('ul#menu > li > a, #offer-nav a', { fontFamily: 'arial', hover: true });
		jQuery('.flexo-link').removeClass('flexo-link');
		ym = window.location.toString();
		ym = ym.replace(/\//g,'').match(/\d+/).toString();
		year = (ym.substr(0,4).length>0)?ym.substr(0,4):'';	
		month = (ym.substr(4,2).length>0)?ym.substr(4,2):'';	
		(month.length == 0)?jQuery('#flexo-'+year).parent().addClass('current_page_item'):jQuery('#flexo-'+year).parent().addClass('current_page_parent');
		jQuery('#flexo-'+year).parents('ul').children().find('a').each(function () {
			if (jQuery(this).attr('href').replace(/\//g,'').match(ym)) {
				jQuery(this).addClass('current_page_item');
			}
		});
	} catch(err) {}
	jQuery('.totop').click(function () {
		scroll(0,0);
		return false;
	});
	jQuery('ul#menu > li > a').each(function () {
		jQuery(this).prepend('<span class="ca cl" /><span class="ca cr" />');
	});
	jQuery('ul#menu > li > ul').after(function () {
		jQuery(this).append('<span class="submenu-end" />');
	});
	jQuery('#menu > li').mouseover(function () {
		jQuery(this).children('.ca').show();
	});
	jQuery('#menu > li').mouseout(function () {
		jQuery(this).children('.ca').hide();
	});
	jQuery('#banner .flash').flash({
		src: '/wp-content/uploads/banner.swf',
		width: 962,
		height: 212,
		wmode: 'transparent'
	});
	jQuery('#banner .flash').css('margin-top','-1px');
	jQuery('#offer').before('<div id="offer-nav"><div id="offer-nav-left" />').cycle({ 
		fx:     'scrollHorz', 
		speed:  800, 
		timeout: 0, 
		pager:  '#offer-nav'
	});
	jQuery('#menu > li > ul').hide();
	jQuery('#menu > li').hoverIntent(hoverIn,hoverOut);
	jQuery('.category_list > li > ul').hide();
	jQuery('.category_list > li.current_cat > ul').show();
	jQuery('.category_list > li > a').click(function () {
		jQuery(this).next('ul').addClass('list_toogle').animate({height: 'toggle'}, 400);
		if (jQuery(this).next('ul').hasClass('list_toogle') ) { return false; }
	});	
	jQuery('ol li').each(function () {
		jQuery(this).wrapInner('<span />');
	});
	jQuery('td, th').each(function () {
		if (jQuery(this).html() == '') {jQuery(this).html('&nbsp;')};
	});
	jQuery('.wp-pagenavi').css('margin-right',(jQuery('.wp-pagenavi').parent().width()-jQuery('.wp-pagenavi').width())/2);
	jQuery('.ngg-gallery-thumbnail a').lightBox();
});

jQuery(window).load(function(){
	$('#loader').remove();
});


function validateForm(current)
{	
	current = jQuery('#'+current+' label');
	validate = true;
	jQuery(current).each(function () {
		if ( (jQuery(this).next().val().indexOf(jQuery(this).html())!=-1) || (jQuery(this).next().val().length<1 ) ) {
			jQuery(this).next().addClass('invalid');
			validate = false;
		} else  if ((jQuery(this).next().attr('name') == 'ne') && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(jQuery(this).next().val())) ) {
			jQuery(this).next().addClass('invalid');
			validate = false;
		} else {
			jQuery(this).next().removeClass('invalid');
		}
	});
    return validate;
}

function resetForm(current)
{	
	current = jQuery('#'+current+' label');
	jQuery(current+' label').each(function () {
		jQuery(this).next().val(jQuery(this).html());
		jQuery(this).next().attr('rel',jQuery(this).html());
		jQuery(this).hide();
	});
    return true;
}

function hoverIn(){ jQuery(this).children('ul').animate({height: 'toggle'}, 400);}
function hoverOut(){ jQuery(this).children('ul').animate({height: 'toggle'}, 400);}
