var oTickerTimeOut;

$(document).ready(function(){

	renderTexts();
	
	renderFormTips();
	
	$("ul.sf-menu").supersubs({ 
        minWidth:    12,
        maxWidth:    27,
        extraWidth:  1
    }).superfish();
	
	// external links hack
	$('a.lnkExternal').click( function(){	window.open(this.href,'_blank'); return false;});
	
	// links outline hack 
	$("a, label, input[type='submit'], input[type='checkbox'], input[type='radio']").bind('focus',function(){if(this.blur)this.blur();});
	// pointer on submit buttons
	$("input[type='submit']").css('cursor', 'pointer');
	
	$.nyroModalSettings({
		minHeight: 150,
		closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="Zamknij">Zamknij</a>',
		endShowContent: function(){
			renderTexts();
		},
		css: {
		    wrapper: {
		      width: '50px',
		      height: '50px'
		    }
		  }
	});
	
	$('#conPrograms').height();
	
	var iMaxUlHeight = 0;
	
	$('#conPrograms .conOneBlock').each(function (i) {
		iMaxUlHeight = ($(this).find('ul').height() > iMaxUlHeight ? $(this).find('ul').height() : iMaxUlHeight = iMaxUlHeight);
	});
	
	$('#conPrograms').height(135+iMaxUlHeight+'px');
	
	$('#conPrograms .conOneBlock').hover(
			function () {
				$(this).css('cursor', 'pointer').fadeTo(100, 0.75);
				$(this).find('ul').show('fast');
		    }, 
		    function () {
		    	$(this).css('cursor', 'auto').fadeTo(100, 1);
		    	$(this).find('ul').hide('fast');
		    }
	);
	
	loadTicker(false, true);
	
});

function sendForm(sFormID){
	$('#'+sFormID).submit();
}

function renderTexts() {
	
	if($.browser.msie) return false;
	
	Cufon.replace('.lnkToCufon', {
		fontFamily: 'Aller',
		hover: true
	});
	
	Cufon.replace('.lnkToCufonGradient', {
		fontFamily: 'Aller',
		hover: {
			color: '-linear-gradient(white, gray)'
		}
	});
	
	Cufon.replace('.txtToCufon', {
		fontFamily: 'Aller'
	});
	
}

function renderFormTips() {
	
	$('input').each(function (i) {
		if($(this).next().attr('class') == 'oHint') {
			$(this).focus(function () {
				$(this).parent().children('span').fadeIn(50);
			}).blur(function () {
				$(this).parent().children('span').fadeOut(50);
			});
		}
	});
	
}

function loadTicker(oLink, bAuto) {
	
	var sLink;
	
	if(oLink) {
		sLink = $(oLink).attr('href');
	} else if(bAuto) {
		
		if($('#lnkTickerNaviNext').attr('href')) {
			sLink = $('#lnkTickerNaviNext').attr('href');
		} else {
			sLink = 'ticker,strona,1.html';
		}
	}
	
	if(sLink != '') {
		 $.ajax({
			 type: "GET",
			 url: sLink,
			 beforeSend: function() {
			 	$('#conTickers').addClass('conAjaxLoading');
			 	$('#conTickersContent').html('');
		 	 },
			 success: function(sHtml){
		 		$('#conTickers').removeClass('conAjaxLoading');
		 		$('#conTickersContent').hide(1, function () { 
		 			$(this).html(sHtml).show("slow");
		 			$('#conTickersContent a.nyroModal').nyroModal();
		 		});
		 	 }
		 });
	}
	
}