function repair_hrefs()
{
    jQuery('#mid_text a').each(function(index) {
        var real_href = jQuery(this).attr("_cke_saved_href");
        if(real_href != null)
        {
            if(real_href.length > 1)
            {
                jQuery(this).attr({
                    "href" : real_href
                });
                jQuery(this).removeAttr("_cke_saved_href");
            }
        }
    });
}

function generate_captcha()
{
    jQuery(document).ready(function()
    {
        jQuery("#send_mail").remove();
        jQuery("#form_mail").append(jQuery("#captcha_table").html());
        jQuery.each(jQuery.browser, function(i, val) {
            if(i=="mozilla")
            {
                jQuery("#table_captcha").css({"width":"82%"});
            }
        });
    })
}

function focuson()
{
    document.form1.number.focus()
}

function check()
{
    if(document.form1.number.value==0)
    {
        alert("Please enter your Category Name");
        document.form1.number.focus();
        return false;
    }
}

jQuery(document).ready(function() {
    jQuery.each(jQuery.browser, function(i, val) {
        if(i=="msie")
        {
            //jQuery("#certyfikaty").css({"margin-left" : "3px"});
        }
        if(i=="mozilla")
        {
            jQuery("#text #top_text ul").css({"top":"10px"});
//            jQuery("#certyfikaty").css({"margin-left" : "9px"});
        }
        if(i=="opera")
        {
            jQuery("#text").css({"margin-left":"5px"});
        }
    });

    //wrong hrefs
    repair_hrefs();
    //lightbox
    jQuery('a[rel=lightbox]').lightBox({
        overlayBgColor: '#FFF',
        overlayOpacity: 0.7,
        imageLoading: 'img/lightbox-ico-loading.gif',
        imageBtnClose: 'img/lightbox-btn-close.gif',
        imageBtnPrev: 'img/lightbox-btn-prev.gif',
        imageBtnNext: 'img/lightbox-btn-next.gif',
        containerResizeSpeed: 350,
        txtImage: 'Zdjęcie',
        txtOf: 'z'
    });
    //rounded corners
    //jQuery("#top_text a").corner("#a8a8a8 6px tl tr");
    //changes content via ajax
    //when we go to page with hash in url
    var hash = window.location.hash;
    var pageId = hash.substr(1,hash.length-1);
    if(pageId.length > 0)
    {
        jQuery.ajax({
            type: "GET",
            url: "get_page_ajax.php",
            cache: false,
            data: "page="+pageId,
            success: function(msg){
                gemius_trash = msg.indexOf('<script type="text/javascript"><!--');
                if(gemius_trash > 0)
                {
                    msg = msg.substr(0,gemius_trash);
                }
                jQuery('#text #mid_text').html(msg);
                repair_hrefs();
            }
        });
    }

    //recaptcha
    jQuery('input#send_mail').click(function() {
        var recaptcha_challenge_field = jQuery("#recaptcha_challenge_field").val();
        var recaptcha_response_field = jQuery("#recaptcha_response_field").val();
        var hidden = '<input type="hidden" name="recaptcha_challenge_field" value="';
        hidden = hidden + recaptcha_challenge_field + '" />';
        hidden = hidden + '<input type="hidden" name="recaptcha_response_field" value="';
        hidden = hidden + recaptcha_response_field + '" />';
        jQuery('#form_mail').append(hidden);
    });

    //oferta menu
    jQuery('#text #top_text li a').click(function() {
        var href = jQuery(this).attr("href");
        var pageId = href.substr(1,href.length-1);
        var html = "";
        jQuery.ajax({
            type: "GET",
            url: "get_page_ajax.php",
            data: "page="+pageId,
            success: function(msg){
                gemius_trash = msg.indexOf('<script type');
                if(gemius_trash > 0)
                {
                    msg = msg.substr(0,gemius_trash);
                }
                jQuery('#text #mid_text').html(msg);
                repair_hrefs();
            }
        });
    });
});
function theRotator() {
//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});

	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({opacity: 1.0});

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds

	setInterval('rotate()',6000);

}

function rotate() {
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

	//Un-comment the 3 lines below to get the images in random order

	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );


	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

};



$(document).ready(function() {
	//Load the slideshow
	theRotator();
	$('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE
});



