$(document).ready(function(){

    $('#baner_arrow_center').css('opacity', 0.6);

    $('#baner_content').cycle({
		 fx: 'fade',
       timeout: 5000,
       cleartypeNoBg: true
	 });

    $('#main_page_produkcje .produkcje_lista').jcarousel({
       vertical: true,
       auto: 3,
       scroll: 1,
       wrap: "circular",
       initCallback: function(carousel) {
          jQuery('#main_page_produkcje .arrow_up').bind('click', function() {
             carousel.prev();
             return false;
          });
          jQuery('#main_page_produkcje .arrow_down').bind('click', function() {
             carousel.next();
             return false;
          });
       }
    });

    $('#main_page_news .news_bg_top, ' + 
       '#news_list .news_bg, #news_list .news_bg_top, #news_list .news_bg_left, ' + 
       '#news_list .news_date_bg, #news_list .news_bg_bottom, .paging .paging_bg'
    ).css('opacity', '0.4');

    $("#topnav > li ").hover(
        function () {
            
            if($(this).children('a').attr('id') == 'news'){var value = '330px';}
            else if ($(this).children('a').attr('id') == 'onas'){var value = '399px'}
            else if ($(this).children('a').attr('id') == 'nasi'){var value = '465px'}
            else if ($(this).children('a').attr('id') == 'impr'){var value = '552px'}
            else if ($(this).children('a').attr('id') == 'prod'){var value = '642px'}
            else if ($(this).children('a').attr('id') == 'real'){var value = '732px'}
            else if ($(this).children('a').attr('id') == 'kont'){var value = '803px'}
            
            var submenu = $(this).children('.submenu');
            if(submenu.length > 0){
                submenu.css({left:0})
                submenu.fadeIn('normaltest');
            }
            
            $('#highlight').css({
                top: '20px',
                left: value
            });
        },
        function () {
            $('#highlight').css({
                top: '-200px'
            });
            $('.submenu').hide();
            
        }
    );

    $('#main_page_horizontal_toolbar_ul').jcarousel({
//       auto: 3,
       scroll: 1,
       wrap: "circular"
    });

    $('#content_list .content_list_filter').hover(function(){
       $('#content_list .content_list_filter_letters').show();
    }, function(){
       $('#content_list .content_list_filter_letters').hide();
    })

    $('#news_list .news_bg').height(window.news_count * 116);
    $('#news_list .news_bg_left').height(window.news_count * 116);
    $('#news_list .news_bg_bottom').height(window.news_count * 1 + 3);

    if($('#contact_map').length > 0)
    {
       mapInitialize();
    }
    

    /*$('#content_detal img.content_img').each(function() {
       // total += $(this).width();
        alert($(this).width());
      });*/
    
    $("div.persons").html("<img class='albert_logo' src='/frontend/templates/site/img/albert_dark_logo.png' alt='Albert' title='Albert'/>");

    $(window).load(function() {
	    $('#content_detal .content_text').css({
	       'width': 816 - $('#content_detal .content_img').width() + 'px',
	       'float': 'right'
	    });
	
	    $('#news_detal .news_text').css({
	       'width': 816 - $('#news_detal .news_img').width() + 'px',
	       'float': 'right'
	    });
    });
    $("#wysuwane").css("left","-210px");
    var hideTimeout = 500;
    var hideDelayTimer=null;
    $("#likebox_slider").hover(function () {
        if(hideDelayTimer) clearTimeout(hideDelayTimer);
        $("#likebox_slider").animate({left: "0px"}, hideTimeout );
        $(this).addClass("likebox_zamknij");
    },function () {
        if(hideDelayTimer) clearTimeout(hideDelayTimer);
        hideDelayTimer=setTimeout(function(){
            hideDelayTimer=null;
            $("#likebox_slider").animate({left: "-199px"}, hideTimeout );
            $(this).removeClass("likebox_zamknij");
        },hideTimeout);
    });
});

function mapInitialize() {
   var latlng = new google.maps.LatLng(parseFloat($('#map_cord_x').val()), parseFloat($('#map_cord_y').val()));
   var myOptions = {
      zoom: parseInt($('#map_zoom').val()),
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   var map = new google.maps.Map(document.getElementById("contact_map"), myOptions);
   var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title: $('#map_marker_title').val()
  });
}
