/* PNG transparency fix for IE6 */

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

/* Funkcja obsluguje glowne menu nawigacyjne */

function createMainMenu(MainNavMenu, MainSubMenu)
{
	$("."+MainNavMenu+" li").mouseover(function() {
		if($(this).children("ul."+MainSubMenu+"").length)
		{
			$("."+MainNavMenu+" li").removeClass("current");
			$("."+MainNavMenu+" li ul."+MainSubMenu+"").hide();
			$(this).addClass("current");
			$(this).children("ul."+MainSubMenu+"").show();
		}
		else
		{
			$("."+MainNavMenu+" li").removeClass("current");
			$(this).addClass("current");
			$("."+MainNavMenu+" li ul."+MainSubMenu+"").hide();
		}
		
	});
}

/* Funkcja obsluguje pokazywanie sie elementow side ToolBar */

function createSideToolBar()
{
	$(".ToolbarDiv li a").click(function() {
		if($(this).parent().children("div.ToolbarItem").length)
		{
			$("div.ToolbarItem").hide();
			
			if( $(this).parent().children("a").hasClass('set') ){
				$(this).parent().children("div.ToolbarItem").hide();
				$(this).parent().children("a").removeClass("set");
			}
			else{
				$(".ToolbarDiv li a").not($(this).parent().children("a")).removeClass("set");
				$(this).parent().children("a").addClass("set");
				$(this).parent().children("div.ToolbarItem").show('slow');
			}

		}
		else{
			$("div.ToolbarItem").hide();
			$(".ToolbarDiv li a").removeClass("set");						
		}
		
	});
}

/* Funkcja obsluguje pokazywanie/ukrywanie elementow EMBED */

function activateEMBEDareas(){	

	$(".embedArea").hide();
	
	$(".embed a").click(function() {
		if($(this).parent().children(".embedArea").length) {
			$(this).parent().children(".embedArea").toggle('slow');
		}
	});
}

/* Funkcja obsluguje menu ikonkowe */

function createServicesMenu()
{
	$(".servicesMenu li a").mouseover(function() {
		var klasa = $(this).attr("class");		
		$(".servicesMenu li span").removeAttr("class");	
		$(".servicesMenu li span").addClass(klasa+'_desc');
		$(".servicesMenu li span").show('fast');
		var tt = $(".servicesMenu li span").attr("class");
	});
}

/* Funkcja ustawia domyslne wartosci inputow wyswietlane w okienku */

function changeValueLabel(id)
{
	$(id).focus(function() {
		if(!fieldValues[$(this).attr('name')])
		{
			fieldValues[$(this).attr('name')] = $(this).val();
			$(this).val('');
		}
	});
	
	$(id).blur(function() {
		if($(this).val().length == 0)
		{
			$(this).val(fieldValues[$(this).attr('name')]);
			delete fieldValues[$(this).attr('name')];
		}
	});
}

/* Funkcja wyswietla etykieta pola haslo  */

function changPassValueLabel()
{
	$("#hasloTopPanel").focus(function() {
		if(!fieldValues[$(this).attr('name')])
		{
			fieldValues[$(this).attr('name')] = 'haslo';
			$(this).attr('class', 'inputpass');
		}
	});
	
	$("#hasloTopPanel").blur(function() {
		if($(this).val().length == 0)
		{
			$(this).removeAttr('class');
			delete fieldValues[$(this).attr('name')];
		}
	});	
}

/* Funkcja inicjalizuje tooltips */

function tooltipInit(){
	
	$(".tooltip[title]").tooltip({
		tipClass: 'tooltipSimple',
		offset: [40, 0], 
		direction: 'down', 
		predelay: 150,
		delay: 200,
		effect: 'slide',	
		slideFade: true	

	}).dynamic();
	
}


//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 0.93).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}


/* 
Funkacja obsługuje Główne Menu Nawigacyjne
onmouseover następuje zmiana widoczności kolejnego DIV oraz 
nadanie elementowi głownego menu atrybutu CLASS
*/
function setMenu(id, name) {
	obj = document.getElementById('menu_'+id);
	if(obj){
		obj.className=name;
	}	
	
	var subdiv = document.getElementById('sub_'+id);
	if(subdiv){ $('#sub_'+id).show(); }	
	
}

function loading( el ){
	$("#"+el).html('<span class="loading" style="display: block; float: right;"></span>');
}

/* funkcja obsługuje oddawanie głosu w ankiecie */

function sendVote(the_form, nazwa_pola, div){
	
	/* sprawdzamy czy zaznaczono opcje odpowiedzi */
	for( z=0; z<ankieta_pytania.length; z++){
	
		var statusOK = false;
		var i = document.forms[the_form].elements[ankieta_pytania[z]].length;

		for(a=0; a<i; a++){
			if (document.forms[the_form].elements[ankieta_pytania[z]][a].checked == true ) {
				statusOK = true;
			}
		}
		
		if(statusOK == false){
			alert('sonda - nie wybrano opcji odpowiedzi');
			return false;
		}
	}
	
	/* wysyłamy AJAX z głosami */
	
	var req = mint.Request();
    	           
    req.OnSuccess = function() {
		$('#'+div).html(this.responseText);
    }
               
    req.SendForm(the_form, "includes/lib/ankiety/vote.php");	
	loading(div);
}

/* Funkcja obsługuje przełącznie widoku z formularza na wyniki */

function showAnkietaRes(div, status, ankieta_ID){
	
	loading(div);
	
	$.ajax({
		url: "includes/lib/ankiety/vote.php",
		data: "ankieta_ID="+ankieta_ID+"&status="+status,
		success: function(data){
		    $(this).addClass("done");
			$('#'+div).html(data);
	  }
	});
	
}

/*
Funkcja obsługuje zmianę wielko¶ci fonta na stronie
*/

var tgs = new Array('p','h3','li','a','div');
var szs = new Array( '12px','14px','18px' );
var startsz = '';

function ZmienFontSize( tgs, trgt, inc ) { 
	if (!document.getElementById) return;
	var d = document,cEl = null,sz,i,j,cTags;
	
	sz = inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 2 ) sz = 2;
	startsz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize   = szs[ sz ];
	if (inc==2) cEl.style.lineHeight = '22px';
	else	    cEl.style.lineHeight = '17px';


	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ){ 
			cTags[ j ].style.fontSize = szs[ sz ]; 
			if (inc==2) cTags[ j ].style.lineHeight = '22px';
			else	    cTags[ j ].style.lineHeight = '17px';	


		}
	}
}

