(function($)
{

	
    /*
     * $.import() helper (for javascript importing within javascript).
     */

    $.extend(true,
    {
        import_js_imported : [],
        
        import_js : function(script)
        {
            var found = false;
            for (var i = 0; i < $.import_js_imported.length; i++)
                if ($.import_js_imported[i] == script) {
                    found = true;
                    break;
                }
            
            if (found == false) {
                $("head").append('<script type="text/javascript" src="' + script + '"></script>');
                
                $.import_js_imported.push(script);
            }
        }
    });

    
    $(function()
    {
	
		$(document).ready(function(e){
			$("#butt").click(function(e){
				if(  $('#img1:visible').length > 0){
					$("#img1").fadeOut('slow');
					}
				else{	
					$("#img1").fadeIn('slow');
					}
					});
			$("#butt1").click(function(e){
				if(  $('#img2:visible').length > 0){
					$("#img2").fadeOut('slow');
					}
				else{	
					$("#img2").fadeIn('slow');
					}
				
		});
		
			$(".butt_on").click(function(e){
				$(this).closest(".home_banner").find('img').fadeIn('slow');
			})	
			
			$("#kanketa .btn1").click(function(e){
				var data = {
					'name':$('#kanketa input[name="name"]').val(),
					'number':$('#kanketa input[name="number"]').val(),
					'phone':$('#kanketa input[name="phone"]').val(),
					'address':$('#kanketa input[name="address"]').val(),
					'email':$('#kanketa input[name="email"]').val(),
					'comment':$('#kanketa textarea').val(),
					'sutinku':$('#kanketa input[name="sutinku"]').val()				
				}
				$.ajax ({url:'../kanketa.php', 'type':'POST', 'data':data, dataType: 'json','success':function(resp){
					if(resp.error){
						$(".kanketaerr").html(resp.error);
					}
					else{
						$(".kanketaerr").html('');
						$(".kanketasucc").html('Anketa išsiųsta sėkmingai');
						$("#kanketa").remove();
					}
				}});
				return false;
			});
		});
        // $.import_js('scripts/jquery.timers-1.2.js');
        // $.import_js('scripts/styled_radios_&_checkboxes.1.0.js');
        
        // Styled radios & checkboxes
        //$.styledRadios();
        $.styledCheckboxes();
        
        // Firefox .btn style fix
        if ($.browser.mozilla)
            $("input[type='submit'], input[type='button']").css('padding-bottom', '3px');
        
        /*
         * Homepage
         */
        var banners_change_interval = 14700;
        //5000
        function home_show_banner(holder)
        {
            $("#home_banner_choosers .item_active:visible").each(function()
            {
                var current_index   = $(this).attr('id')
                    .replace('home_banner_chooser_active_', '');
                $("#home_banner_holder_"+current_index).removeClass('holder_active')
                $("#home_banner_holder_"+current_index + " .item_active").fadeOut();
                $("#home_banner_holder_"+current_index + " .item").fadeIn();
                $("#home_banner_"+current_index).fadeOut();
            });
            
            var next_index      = $(holder).attr('id').replace('home_banner_holder_', '');
            $("#home_banner_holder_"+next_index).addClass('holder_active')
            $("#home_banner_holder_"+next_index + " .item").fadeOut();
            $("#home_banner_holder_"+next_index + " .item_active").fadeIn();
            $("#home_banner_"+next_index).fadeIn();
        }
        if ($("#home_banner_choosers .holder").length > 0) {
            $("#home_banner_choosers").everyTime(banners_change_interval, function() {
                if ($(".holder_active", this).nextAll(".holder").length) {
                    home_show_banner($(".holder_active", this).nextAll(".holder"));
                } else {
                    home_show_banner($(".holder:eq(0)", this));
                }
            });                
            
            
            
            $("#home_banner_choosers .holder").each(function()
            {
                var holder = this;
                $(".item", this).click(function()
                {
                    $("#home_banner_choosers").stopTime();
                    home_show_banner(holder);
                });
            });
        }
        
            
        
        // Leftmenu for IE6
        $("#leftmenu a").each(function()
        {
            var a = this;
            $(".item", this).click(function()
            {
                document.location = $(a).attr("href");
            });
        });
        
        
        /*
         * Subscription box
         */
        $("#subscribe_box .subscribed a, #subscribe_box .subscription_exists a").click(function()
            {
                
            });
        
        /*
         * Plan page
         */
        // $(".wysiwyg table tr").each(function()
            // {
                // $("th:first", this).css({
                    // borderRight: '1px solid transparent'
                // });
                // $("th:last", this).css({
                    // borderLeft: '1px solid transparent'
                // });
                // $("th:not(:first):not(:last)", this).css({
                    // borderLeft: '1px solid transparent',
                    // borderRight: '1px solid transparent'
                // });
            // });
        
        
        // Planu puslapiuose, jei per aukstas left_menu ir per mazai inner_content turinio - nesueina borderiai
        // Tokiu atveju padidinam auksti inner_content
        if ($("#leftmenu").height() > $("#inner_content").height()) {
            $('#inner_content').css('cssText', 'height: '+$("#leftmenu").height()+'px !important');
        }
    });
})(jQuery);

// Return false, specially for windows vista ie 7
function retFalse()
{
    try
    {
        // VISTA IE 7
        window.event.returnValue = false;
    } catch (error)
    {
        // ALL OTHER (MOZILLA, OPERA, SAFARI, IE 6 & 7 ON XP)
        return false;
    }
}

function refresh_page_no_post(prefix, suffix)
{
    var d = new Date();
    window.location = prefix + ',no_post.'+d.getTime()+ (suffix != undefined ? suffix : '');
    return retFalse();
}

function skaiciuoti() {
     var tvt = document.getElementById('stv').value;
     var int = document.getElementById('sin').value;
     var att = document.getElementById('sat').value;
     var nuolaida = tvt/12 + int/12 - att/12;
     nuolaida = Math.round(nuolaida);
     if (nuolaida > 10) nuolaida = 10;
     document.getElementById('snuol').innerHTML = nuolaida+'%';
}


function ch(id, tlin, cl){
		
    var pozicija = document.body.scrollTop;	
    if (pozicija == 0){ if (window.pageYOffset)	pozicija = window.pageYOffset; 	else   	pozicija = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0; }  pozicija=pozicija+1;
    var pozicija2=pozicija-2;

    document.getElementById(id).style.display='block';
    var aukstis = document.getElementById(id).offsetHeight; 
    if (!aukstis) {aukstis = 400}
    aukstis = aukstis+15;
    
    document.getElementById(id).style.display='none';
    var braukstis = document.documentElement.clientHeight-70;
    
    if (!braukstis) {braukstis = 400;}
    if (aukstis > braukstis){aukstis = braukstis; var mright="30"}else{var mright="15";}	

    if (cl){var plotis = cl;}else{var plotis = "500";}
    
    
    
    
    if (document.getElementById("home_main_left")){
	    var kur1 = "home_main_left";
    }else{
	    var kur1 = "inner_main";
    }
    
    $.floatbox({
        content: document.getElementById(id).innerHTML,
        aukstis: document.getElementById(kur1).offsetHeight+280,
        baukstis: aukstis,
        pozicija: pozicija,
        pozicija2: pozicija2,
        plotis: plotis,
        mright: mright,
        fade: true
    });	
    

}
