var interval = null;
/*lightbox */
$( function() {
    /*$('#tellBtt').prettyPhoto({
        hideflash:true,
        custom_markup: '<div id="tellWrap"></div>',
        keyboard_shortcuts: false
    });*/
    $('a[rel^=\'prettyPhoto\']').prettyPhoto({
        slideshow:5000,
        keyboard_shortcuts: false,
        inline_markup: '<div class="pp_inline clearfix" width="{width}">{content}</div>',
        default_width: 700,
        overlay_gallery: false,
 theme: 'light_square'
    });
    
    $('[rel=lightbox],.fullNews .img .min, #offer .img, .program .img .min').prettyPhoto( {
        theme: 'light_square',
        keyboard_shortcuts: false
    } );

} );
/**shadow left **/
$(function() {
    $('.left h2').each(function() {
        var txt = $(this).text();
        $(this).html('<span class="t">' + txt + '</span><span class="sh">' + txt + '</span>');
    });
});
/*news */
$(function() {
    $('.newsBox .more').click( function() {
        if($('#home').get().length>0) {
            return true;
        }
        $(this).parent().parent().find('.full').slideDown();
        $(this).slideUp();
        $('.newsBox .back').css('display', 'block');
        return false;
    } );
    $('.newsBox .img a').click(function() {
        $(this).parent().parent().find('.more').click();
        return false;
    });
    $('.newsBox .back').each(function() {
        if($(this).parent().parent().hasClass('fullNews')) {
            return;
        }
        $(this).click( function() {
            $(this).hide();

            $(this).parent().slideUp('normal', function() {
                $(this).parent().find('.more').slideDown();
            });
            return false;
        } )
    } );
});

/*
 * Contact Form
 */
$(function() {
    $('#searchbox .s').hide();
    $('#searchUp').click(function() {
        if($('#searchbox .s').is(':visible')) {
            $('#searchbox .s').slideUp(300);
        } else {
            $('#searchbox .s').slideDown(300);
        }
    });
    $('#searchbox .s input:checked').parent().addClass('active');
    $('#searchbox .s label').click(function () {
        $('#searchbox .s label.active').removeClass('active');
        $(this).addClass('active');   
        $('#searchbox .s').slideUp(); 
    });
});
$( function() {
    $('#searchBox .text, #newForm .text, #newForm textarea, .form .text, textarea').each(function() {
        if($(this).attr('value') == '') {
            $(this).attr('value', $(this).attr('defaultText'));
            
        }
    }).focus( txtinputFocus ).blur( txtinputBlur );
    $('.txtinput, #phone .t, #contactForm .text, textarea').each( function() {
        $(this).focus( txtinputFocus ).blur( txtinputBlur );
    } );
    
    $("input[type=file]").filestyle({
        image: "images/select.gif",
        imageheight : 22,
        imagewidth : 78,
        width : 150
    });

} );
function txtinputFocus() {

    if($(this).attr('defaultText') == $(this).attr('value'))
        $(this).attr('value','');

    
}

function txtinputBlur() {

    if($(this).attr('value') == '')
        $(this).attr('value', $(this).attr('defaultText') );

    
}
$(function() {
    
    var sum = 1;
    var max = 990;
    var all = 0
    
    $('#menu .firstLevel').each(function() {
        all++;
        sum += $(this).outerWidth(true) - 1 ;
    });
    
    var el = Math.floor((max-sum)/all/2);
    $('#menu .firstLevel').css('padding', '0px ' + (el+20) + 'px');
    //alert((max - sum - (2*el*all) + 20 + el));
    
    
    $('#menu .first .firstLevel').css('paddingLeft', (max - sum - (2*el*all) + 20 + el) + 'px');
});

$(function() {
    
    var sum = 1;
    var max = 690;
    var all = 0
    
    $('#footer .menu a').each(function() {
        if($(this).is(':has(img)')) {
            return;
        }
        all++;
        
        sum += $(this).outerWidth(true);
    });
    sum += (all-1)*10;
    
    var el = Math.floor((max-sum)/all/2);
    $('#footer .menu a').each(function() {
        if($(this).is(':has(img)')) {
            return;
        }
        $(this).css('padding', '0px ' + (el+15) + 'px');
    });
    //alert((max - sum - (2*el*all) + 20 + el));
    
    
    //$('#menu .first .firstLevel').css('paddingLeft', (max - sum - (2*el*all) + 20 + el) + 'px');
});
$(function() {
    $('#newsletter').parent().submit(function() {
        var data = {};
       
        data.email = $(this).find('[name=mail]').attr('value');
        data.newsletter = 1;
        if($(this).find('[name=remove]').is(':checked')) {
            data.remove = 1;
        }
        $.post($(this).attr('action'), data, function(data) {
            $('#newsletter').html(data);
        }, 'text');
        return false;
    });
});

$(  function() {
    $('#top img').css( 'opacity', 0 );
    setTimeout( function() {
        $( '#top img' ).animate({
            opacity: 1
        }, 1000);
    }, 600 );


});
$(function() {
    if($('.left .random').get().length) {
        $('.left .random').wrap('<div class="wrapOuter"></div>');
        
        setTimeout(nextRandom, 7000);
    }
});
function nextRandom() {
    $.get('index.php', {
        'random':1
    }, nextRandomCallback, 'text');
}
function nextRandomCallback(data) {
    var ht = $(data).find('.random');
    $('.wrapOuter').height(210);
    var height = $('.wrapOuter').height();
    //alert(data);
    $('.left .random').css({
        height: height +'px',
        position: 'absolute',
        top: '0px',
        left: '0px',
        width: '100%',
        overflow: 'hidden'
    }).animate({
        top:height + 'px'
    }, 400, function() {
        $(this).remove();
        setTimeout(nextRandom, 7000);
    });
    ht.css({
        height: height +'px',
        position: 'absolute',
        width: '100%',
        top: '-' + height+ 'px',
        left: '0px',
        overflow: 'hidden'
    })
    $('.wrapOuter').append(ht);
    ht.animate({
        top: '0px'
    }, 400, function() {
        $(this).css({
            position: 'relative',
            height: 'auto'
        });
    })
}

$(function() {
    $('#menu .linkWrap').hover(function() {
        $(this).addClass('hover');
        if($(this).attr('maxHeight') == null) {
            $(this).attr('maxHeight', $(this).find('ul').height());
            $(this).find('ul').height(0);
            
        }
        $(this).find('ul').stop().animate({
            height: $(this).attr('maxHeight') + 'px'
        }, 'fast');
    }, function() {
        $(this).removeClass('hover');
        $(this).find('ul').stop().animate({
            height: '0px'
        }, 'fast', function() {
        });
    }).click(function() {
        window.location = $(this).find('.firstLevel').attr('href');
    });
});

(function($){
    $.fn.filestyle=function(options){
        var settings={
            width:250
        };

        if(options){
            $.extend(settings,options);
        };

        return this.each(function(){
            var self=this;
            var wrapper=$("<div>").css({
                "width":settings.imagewidth+"px",
                "height":settings.imageheight+"px",
                "background":"url("+settings.image+") 0 0 no-repeat",
                "background-position":"right",
                "display":"inline",
                "position":"absolute",
                "overflow":"hidden"
            });
            var filename=$('<input class="file">').addClass($(self).attr("class")).css({
                "display":"inline",
                "width":settings.width+"px"
            });
            $(self).before(filename);
            $(self).wrap(wrapper);
            $(self).css({
                "position":"relative",
                "height":settings.imageheight+"px",
                "width":settings.width+"px",
                "display":"inline",
                "cursor":"pointer",
                "opacity":"0.0"
            });
            if($.browser.mozilla){
                if(/Win/.test(navigator.platform)){
                    $(self).css("margin-left","-142px");
                }else{
                    $(self).css("margin-left","-168px");
                };

            }else{
                $(self).css("margin-left",settings.imagewidth-settings.width+"px");
            };

            $(self).bind("change",function(){
                filename.val($(self).val());
            });
        });
    };

})(jQuery);

