jQuery(document).ready(function(){
	// try {
		// Cufon.replace('', { fontFamily: 'trebuchet' });
		// Cufon.replace('', { fontFamily: 'trebuchet', hover: true });
	// } catch(err) {}
	
	jQuery('.totop').click(function () {
		scroll(0,0);
		return false;
	});
	
	if (jQuery('#customers div').size() > 1) {
		jQuery('#customers').before('<a href=#prev" id="customers-prev">Poprzedni</a><a href=#next" id="customers-next">Następny</a>')
	}
	jQuery('#customers').cycle({ 
		fx:     'scrollHorz', 
		speed:  800, 
		timeout: 8000, 
		prev: '#customers-prev',
		next: '#customers-next'
	});
	
    jQuery('.menu li a').not('.menu li.current_page_item a, #menu-menu-pomocnicze li:first a, #menu-menu-stopka li a')
        .css( {backgroundPosition: "50% 0%"} )
        .mouseover(function(){
            jQuery(this).stop().animate({backgroundPosition:"(50% 100%)"}, {duration:400})
        })
        .mouseout(function(){
            jQuery(this).stop().animate({backgroundPosition:"(50% 100%)"}, {duration:200, complete:function(){
                jQuery(this).css({backgroundPosition: "50% 0%"})
            }})
        });
	jQuery('.menu li a').click(function () {
		jQuery('.current_page_item').removeClass('current_page_item');
		jQuery(this).parents('li').addClass('current_page_item');
	});
	
	jQuery('label.hide').hide().each(function () {
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').val(jQuery(this).html());
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').attr('rel',jQuery(this).html());
		jQuery(this).hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').focus(function () {
		if (jQuery(this).val()==jQuery(this).attr('rel')) jQuery(this).val('');
		jQuery(this).removeClass('invalid');
		jQuery(this).addClass('focus');
		jQuery(this).parents('form').find('.error').hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').blur(function () {
		if (jQuery(this).val()=='') jQuery(this).val(jQuery(this).attr('rel'));
		jQuery(this).removeClass('focus');
	});
	
	jQuery('#advert_link').fancybox({
		'scrolling': 'no', 
		'titleShow': false, 
		'overlayOpacity':'1',
		'overlayColor':'#f28e11',
		'onComplete': startAdverts
	});
	//jQuery('#advert_link').click();
	jQuery('.toggle').hoverIntent(toggleIn,toggleOut);
	
	try {		
		var cnt = 0;
		var sumQ = 0;
		var cntQ = 1;
		var qtyQ = jQuery('#page_slider_quiz li').size();
		jQuery('#page_slider_quiz li').each(function () {
			cnt = cnt + 1;
			jQuery(this).find('h3').prepend('<span class="cnt">'+cnt+'. </span>');
		});
		jQuery('#page_slider_quiz').before('<a href="#następny" id="page_slider_quiz_next">Następne pytanie</a><a href="#następny" id="page_slider_quiz_prev">Poprzednie pytanie</a>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			next: '#page_slider_quiz_next',
			prev: '#page_slider_quiz_prev',
			cleartypeNoBg: true
		});
		jQuery('#page_slider_quiz_next, #page_slider_quiz_prev, #page_slider_quiz_results').hide();
		jQuery('#page_slider_quiz .radio').removeAttr('checked');
		jQuery('#page_slider_quiz .radio').click(function () {
			sumQ = sumQ + parseInt(jQuery(this).val());
			cntQ = cntQ + 1;
			if (cntQ >= 1) {
				jQuery('#page_slider_quiz_prev').show();
			} else {
				jQuery('#page_slider_quiz_prev').hide();
			}
			if (qtyQ > cntQ) {
				jQuery('#page_slider_quiz_next').click();
			} else {
				jQuery('#page_slider_quiz, .entry, h2').hide()
				jQuery('.page_slider_quiz_results').each(function () {
					jQuery(this).find('h3').prepend('Twój wynik to: '+sumQ+' - ');
				});
				if (sumQ >= 46) {
					jQuery('.page_slider_quiz_results').eq(0).show();
				} else  if (sumQ >= 23 && sumQ <= 45) {
					jQuery('.page_slider_quiz_results').eq(1).show();
				} else {
					jQuery('.page_slider_quiz_results').eq(2).show();
				}
			}
		});
		jQuery('#page_slider_quiz_prev').click(function () {
			cntQ = cntQ - 1;
			if (cntQ <= 1) {
				jQuery(this).hide();
			}
		});
	} catch(err) {}	
	
	
	try {		
		jQuery('#page_slider').before('<a href="#następny" id="page_slider_next">Następny</a><a href="#poprzedni" id="page_slider_prev">Poprzedni</a><div id="page_slider_pagination"></div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			pager:  '#page_slider_pagination', 
			next: '#page_slider_next',
			prev: '#page_slider_prev',
			cleartypeNoBg: true
		});
	} catch(err) {}	
	
	try {		
		jQuery('#page_slider_faq').before('<a href="#następny" id="page_slider_next">Następny</a><a href="#poprzedni" id="page_slider_prev">Poprzedni</a><div id="page_slider_pagination">następna</div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			next: '#page_slider_next',
			prev: '#page_slider_prev',
			cleartypeNoBg: true
		});
	} catch(err) {}	
	
	try {		
		jQuery('#natural').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			pager:  '#natural_nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<a href="#" id="'+jQuery(slide).attr('id')+'_link"></a>'; 
			},
			cleartypeNoBg: true
		});
		jQuery('#natural_julita').hide(); 
	} catch(err) {}	
	
	//jQuery('#page_slider_pagination a').eq(6).click();
	
	jQuery('label.hide').hide().each(function () {
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').val(jQuery(this).html());
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').attr('rel',jQuery(this).html());
		jQuery(this).hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').focus(function () {
		if (jQuery(this).val()==jQuery(this).attr('rel')) jQuery(this).val('');
		jQuery(this).removeClass('invalid');
		jQuery(this).addClass('focus');
		jQuery(this).parents('form').find('.error').hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').blur(function () {
		if (jQuery(this).val()=='') jQuery(this).val(jQuery(this).attr('rel'));
		jQuery(this).removeClass('focus');
	});
	
	jQuery('#commentform #name, #commentform #surename').keyup(function () {
		jQuery('#commentform #author').val(jQuery('#commentform #name').val()+' '+jQuery('#commentform #surename').val());
	});
	jQuery('#commentform').submit(function () {
		jQuery('.wpcf7-not-valid-tip').remove();
		valid = true;
		emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		jQuery('#commentform .text').each(function () {
			if (jQuery(this).val()=='' || (jQuery(this).attr('id')=='email' && !emailFilter.test(jQuery(this).val()))) {
				valid = false;
				jQuery(this).after('<span class="wpcf7-not-valid-tip hide">Proszę wypełnić wszystkie pola</span>')
				jQuery(this).next('.wpcf7-not-valid-tip').animate({height:'show'},200);
				jQuery('.wpcf7-not-valid-tip').mouseover(function () {
					jQuery(this).animate({height:'hide'},200);
					setTimeout("jQuery(this).remove()",201);
				});
				jQuery(this).mouseover(function () {
					jQuery(this).next('.wpcf7-not-valid-tip').animate({height:'hide'},200);
					setTimeout("jQuery(this).next('.wpcf7-not-valid-tip').remove()",201);
				});
			}
		});
		if (valid) {
			jQuery('.wpcf7-response-output').remove()
			jQuery('#commentform').append('<div class="wpcf7-response-output wpcf7-mail-sent-ok hide">Pytanie zostało przekazane do moderacji. Potwierdź je klikając w link wysłany mailem na adres podany w formularzu.</div>');
			jQuery('.wpcf7-response-output').animate({height:'show'},200);
			setTimeout("jQuery('.wpcf7-response-output').hide(200)",5000);
			setTimeout("jQuery('.wpcf7-response-output').remove()",5201	);
			return true;
		} else {
			jQuery('#commentform').append('<div class="wpcf7-response-output wpcf7-validation-errors wpcf7-mail-sent-ng hide">Wystąpił błąd. Sprawdź poprawność pól i wyślij ponownie.</div>');
			jQuery('.wpcf7-response-output').animate({height:'show'},200);
			return false;
		}
		return valid;
	});
});


jQuery(window).load(function(){
	jQuery('#home').animate({height: '550px'}, 800);
	itemShow('#osc','width',800,0);
	itemShow('#family','opacity',800,400);
	itemShow('#zbyszek','width',800,1600);
	itemShow('#julita','width',800,1600);
	itemShow('#oskar','width',800,1600);
	itemShow('#box_prof','height',800,800);
	itemShow('#box_prod','height',800,1200);
	itemShow('#box_award','height',800,1600);
	itemShow('#home_content','width',800,2000);
	itemShow('#footer','height',800,2000);
	
	itemShow('#natural_zbyszek_link','opacity',800,200);
	itemShow('#natural_oskar_link','opacity',800,600);
	itemShow('#natural_julita_link','opacity',800,1000);
	itemShow('#natural_julita','opacity',800,1000);
});


function startAdverts() {
	try {		
		jQuery('#advert_slider').after('<div id="advert_slider_nav"></div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			pager:  '#advert_slider_nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<a href="#" title="'+jQuery(slide).find('a').attr('id')+'">'+jQuery(slide).attr('title')+'</a>'; 
			},
			cleartypeNoBg: true,
			after: startAdvert
		});
		startAdvert();
	} catch(err) {}	
}

function startAdvert() {
	flowplayer('advert_2', "wp-content/uploads/flowplayer-3.2.5.swf", { 
	
		clip: { 
			autoPlay: true, 
			autoBuffering: true ,  
			url: "http://boiron.pl.s3.amazonaws.com/reklama/osciilo_ipad.flv"
		}, 
		content: {width:551, height:301, top:0, left: 0} 
	});
}
		
function itemShow(name, effect, duration, timeout) {
	setTimeout("jQuery('"+name+"').animate({"+effect+": 'show'}, "+duration+");",timeout);
}
function toggleIn(){ 
	jQuery(this).next('.hide_toggle').animate({height: 'show'}, 400);
}
function toggleOut(){ 
	jQuery(this).next('.hide_toggle').animate({height: 'hide'}, 400);
}

function loadFlutrends() {
	data2004 = [[20040101,0],[20040201,0],[20040301,0],[20040401,0],[20040501,0],[20040601,0],[20040701,0],[20040801,0],[20040926,19],[20041003,28],[20041010,61],[20041017,62],[20041024,57],[20041031,56],[20041107,56],[20041114,48],[20041121,49],[20041128,46],[20041205,43],[20041212,44],[20041219,40],[20041226,43]];
	data2005 = [[20050102,47],[20050109,52],[20050116,53],[20050123,62],[20050130,271],[20050206,392],[20050213,423],[20050220,404],[20050227,466],[20050306,442],[20050313,267],[20050320,182],[20050327,156],[20050403,98],[20050410,76],[20050417,59],[20050424,49],[20050501,43],[20050508,36],[20050515,32],[20050522,29],[20050529,25],[20050605,22],[20050612,20],[20050619,18],[20050626,17],[20050703,16],[20050710,14],[20050717,13],[20050724,12],[20050731,12],[20050807,12],[20050814,12],[20050821,12],[20050828,12],[20050904,14],[20050911,23],[20050918,37],[20050925,61],[20051002,75],[20051009,109],[20051016,122],[20051023,88],[20051030,66],[20051106,66],[20051113,60],[20051120,57],[20051127,49],[20051204,53],[20051211,49],[20051218,51],[20051225,50]];
	data2006 = [[20060101,54],[20060108,54],[20060115,51],[20060122,55],[20060129,57],[20060205,55],[20060212,63],[20060219,79],[20060226,93],[20060305,116],[20060312,150],[20060319,130],[20060326,116],[20060402,115],[20060409,82],[20060416,57],[20060423,43],[20060430,37],[20060507,32],[20060514,28],[20060521,24],[20060528,23],[20060604,23],[20060611,21],[20060618,19],[20060625,19],[20060702,17],[20060709,16],[20060716,15],[20060723,14],[20060730,13],[20060806,13],[20060813,12],[20060820,12],[20060827,11],[20060903,10],[20060910,12],[20060917,22],[20060924,44],[20061001,49],[20061008,52],[20061015,61],[20061022,76],[20061029,70],[20061105,57],[20061112,50],[20061119,47],[20061126,46],[20061203,46],[20061210,45],[20061217,42],[20061224,36],[20061231,37]];
	data2007 = [[20070107,41],[20070114,49],[20070121,54],[20070128,67],[20070204,136],[20070211,141],[20070218,194],[20070225,216],[20070304,232],[20070311,159],[20070318,116],[20070325,87],[20070401,61],[20070408,51],[20070415,40],[20070422,36],[20070429,32],[20070506,26],[20070513,22],[20070520,21],[20070527,19],[20070603,16],[20070610,16],[20070617,14],[20070624,13],[20070701,11],[20070708,11],[20070715,10],[20070722,10],[20070729,9],[20070805,9],[20070812,8],[20070819,8],[20070826,8],[20070902,9],[20070909,12],[20070916,26],[20070923,56],[20070930,55],[20071007,49],[20071014,46],[20071021,53],[20071028,59],[20071104,60],[20071111,52],[20071118,45],[20071125,49],[20071202,48],[20071209,47],[20071216,50],[20071223,47],[20071230,48]];
	data2008 = [[20080106,67],[20080113,82],[20080120,109],[20080127,98],[20080203,109],[20080210,97],[20080217,136],[20080224,126],[20080302,128],[20080309,99],[20080316,85],[20080323,71],[20080330,78],[20080406,63],[20080413,49],[20080420,40],[20080427,33],[20080504,30],[20080511,26],[20080518,23],[20080525,21],[20080601,21],[20080608,19],[20080615,17],[20080622,15],[20080629,14],[20080706,12],[20080713,11],[20080720,11],[20080727,10],[20080803,9],[20080810,9],[20080817,8],[20080824,8],[20080831,8],[20080907,9],[20080914,21],[20080921,68],[20080928,65],[20081005,53],[20081012,46],[20081019,45],[20081026,43],[20081102,39],[20081109,36],[20081116,37],[20081123,43],[20081130,61],[20081207,71],[20081214,67],[20081221,71],[20081228,100]];
	data2009 = [[20090104,120],[20090111,179],[20090118,357],[20090125,432],[20090201,347],[20090208,228],[20090215,143],[20090222,97],[20090301,94],[20090308,76],[20090315,66],[20090322,58],[20090329,46],[20090405,39],[20090412,33],[20090419,29],[20090426,157],[20090503,88],[20090510,50],[20090517,39],[20090524,30],[20090531,25],[20090607,22],[20090614,20],[20090621,19],[20090628,18],[20090705,18],[20090712,17],[20090719,16],[20090726,16],[20090802,17],[20090809,18],[20090816,18],[20090823,20],[20090830,21],[20090906,25],[20090913,48],[20090920,75],[20090927,68],[20091004,54],[20091011,50],[20091018,58],[20091025,79],[20091101,203],[20091108,251],[20091115,486],[20091122,410],[20091129,273],[20091206,194],[20091213,124],[20091220,83],[20091227,67]];
	data2010 = [[20100103,59],[20100110,51],[20100117,44],[20100124,40],[20100131,36],[20100207,34],[20100214,35],[20100221,33],[20100228,31],[20100307,28],[20100314,27],[20100321,25],[20100328,22],[20100404,20],[20100411,18],[20100418,16],[20100425,14],[20100502,13],[20100509,13],[20100516,13],[20100523,12],[20100530,12],[20100606,12],[20100613,12],[20100620,11],[20100627,10],[20100704,9],[20100711,9],[20100718,8],[20100725,8],[20100801,7],[20100808,7],[20100815,7],[20100822,6],[20100829,6],[20100905,8],[20100912,14],[20100919,41],[20100926,44],[20101003,38],[20101010,34],[20101017,34],[20101024,34],[20101031,31],[20101107,29],[20101114,28],[20101121,27],[20101128,29],[20101205,32],[20101212,38],[20101219,42],[20101226,54]];
	data2011 = [[20110102,97],[20110109,159],[20110116,187],[20110123,200],[20110130,186],[20110206,183],[20110213,126],[20110220,121],[20110227,120],[20110306,102],[20110313,74],[20110320,55],[20110327,42],[20110403,32],[20110410,27],[20110417,23],[20110424,21],[20110501,19],[20110508,17],[20110515,16],[20110522,14],[20110529,14],[20110605,12],[20110612,11],[20110619,10],[20110626,10],[20110703,9],[20110710,8],[20110717,8],[20110724,7],[20110731,7],[20110807,7],[20110814,7],[20110821,7]];
	
	jQuery('#flutrends').before('<select id="flutrends_sel"><option value="data2011">2011</option><option value="data2010">2010</option><option value="data2009">2009</option><option value="data2008">2008</option><option value="data2007">2007</option><option value="data2006">2006</option><option value="data2005">2005</option><option value="data2004">2004</option></select>');
	jQuery('#flutrends_sel').change(function () {
		switch (jQuery(this).val()) {
			case 'data2004': jQuery.plot($('#flutrends'), [ data2004 ]);
			break;
			case 'data2005': jQuery.plot($('#flutrends'), [ data2005 ]);
			break;
			case 'data2006': jQuery.plot($('#flutrends'), [ data2006 ]);
			break;
			case 'data2007': jQuery.plot($('#flutrends'), [ data2007 ]);
			break;
			case 'data2008': jQuery.plot($('#flutrends'), [ data2008 ]);
			break;
			case 'data2009': jQuery.plot($('#flutrends'), [ data2009 ]);
			break;
			case 'data2010': jQuery.plot($('#flutrends'), [ data2010 ]);
			break;
			case 'data2011': jQuery.plot($('#flutrends'), [ data2011 ]);
			break;
		}
	
		jQuery('.tickLabel').each(function () {
			(jQuery(this).html().length > 6) ? jQuery(this).html(jQuery(this).html().substr(4,2).replace('01','sty').replace('02','lut').replace('03','mar').replace('04','kwi').replace('05','maj').replace('06','cze').replace('07','lip').replace('08','sie').replace('09','wrz').replace('10','paź').replace('11','lis').replace('12','gru')) : jQuery(this).html();
		});
	});
	jQuery.plot($('#flutrends'), [ data2011 ]);
	
	jQuery('.tickLabel').each(function () {
		(jQuery(this).html().length > 6) ? jQuery(this).html(jQuery(this).html().substr(4,2).replace('01','sty').replace('02','lut').replace('03','mar').replace('04','kwi').replace('05','maj').replace('06','cze').replace('07','lip').replace('08','sie').replace('09','wrz').replace('10','paź').replace('11','lis').replace('12','gru')) : jQuery(this).html();
	});
}
