jQuery(document).ready(function($) {

    var temperature = '';
    var wind = '';

    $.ajax({
        url: "weather.php",
        dataType: "xml",
        success: function(xml, textStatus, jqXHR){
            //console.log($(xml).find('site'));

            $(xml).find('data_item').each(function(){

                var name = $(this).find('name').text();
                if(name=='TEMPERATURE'){
                    //$('#output').append(name + '<br />');
                    temperature = $(this).find('value').text();
                }

                if(name=='WS2A_1'){
                    //$('#output').append(name + '<br />');
                    wind = Math.round(parseInt($(this).find('value').text()) * 0.514444444);

                }

            });

            $("#top-bar").html(temperature + '°C&nbsp;&nbsp;&nbsp;' + wind + 'm/s').animate({top: "0px"},{duration: 1200, easing: 'easeOutBounce'});
        }
    });

    $('#lb-slider-cont').lbSlider();



    /** Menüü hover **/
    $('.menuItem').hover(function(){

        $(this).find('a').addClass('active').find('span').addClass('active');
        $(this).find('.sub-pages').fadeIn(300);

    }, function(){

        $(this).find('a').removeClass('active').find('span').removeClass('active');
        $(this).find('.sub-pages').fadeOut(150);

    });

    var ua = $.browser;

    if ( (ua.mozilla && ua.version.slice(0,3) == "2.0") || (ua.msie && ua.version.slice(0,1) == "9") ) {

    	$('#fluid').width(8).show();

  	}

	

    /** ACCORDION **/

    $('#acc-cont .acc-head').click(function(){

        var textContainer = $(this).parent().find('.acc-text');
        if( textContainer.is(':hidden') ) {
            $('#acc-cont .readMore').hide();
            $('#acc-cont .acc-text:visible').slideUp(300);

            textContainer.slideDown(300, function(){
                textContainer.find('.readMore').fadeIn(400);
            });
        }

    });


    /** CALENDAR - BDAY **/
    $('#birthday').bind("mouseleave",function(){

        $(this).fadeOut(300).unbind("mouseleave");;
        $('#cake').fadeIn(300);

        $('#cake').hover(function(){
            $('#birthday').fadeIn(500);
            $('#events').fadeOut(500);
        }, function(){
            $('#birthday').fadeOut(500);
            $('#events').fadeIn(500);
        });    

    });

    


    /** Gallery hover **/
    var isIE = jQuery.browser.msie;
    $('#gallery-container .galleryItem a').hover(function(){
        //alert('as');
        if(isIE){
            $(this).find('.innerShadow').show();
        }else{
            $(this).find('.innerShadow').fadeIn(400);
        }
    }, function(){
        if(isIE){
            $(this).find('.innerShadow').hide();
        }else{
            $(this).find('.innerShadow').fadeOut(400);
        }
    });

    $("a[rel=galerii]").fancybox({'overlayColor' : '#000'});

});

