$(document).ready(  
function(){

// main_sidebar
$("#main_squares .main_item").hover(function(){
    var description = $(this).attr('data-description');
    $(".main_sidebar .pos p").text(description);
});

// main_content
$(".main_content .item span").css({
	opacity: 0.7
});

// typy wyswietalania schodow
if($("#content  #list").length>0){

	// sortowania
	var text_list_img = $("#list .item:eq(0) a img").attr("src");
	$("#taxonomy #list").after('<div id="text_list"><ul></ul><div id="text_list_img"><img src="'+text_list_img+'" /></div></div><br />');
	$("#list .item").each(function(){
		tekst = $(this).text();
		href = $(this).children("a").attr("href");
		$("#text_list ul").append('<li><a href="'+href+'">'+tekst+'</a></li>');
	});
	
	$("#list").hide();

	$("#text_list li").hover(function(){
		var pozycja = $("#text_list li").index(this);
		text_list_img = $('#list .item:eq('+pozycja+') a img').attr("src");
		$("#text_list_img img").attr("src",text_list_img);
	});
	
	
	// typ sortowania
	function readCookie(cookieName) {
            var theCookie=""+document.cookie;
            var ind=theCookie.indexOf(cookieName);
            if (ind==-1 || cookieName=="") return "";
            var ind1=theCookie.indexOf(';',ind);
            if (ind1==-1) ind1=theCookie.length;
            return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}
        
        /// czas ciasteczka
        var theDate = new Date();
        var oneYearLater = new Date( theDate.getTime() + 31536000000 );
        var expiryDate = oneYearLater.toGMTString();
        
        
	
	$("#taxonomy #list").before('<div id="switch_type"></div>');
	var switch_type = 0; ///< 1 for list-miniatures, 2 for text_list
        console.log(switch_type);
        /// before clicks
        console.log(readCookie('switch'));
	if (readCookie('switch')==2){
            switch_type=2;
            $("#switch_type").css({"background-position":"0px"});
            $("#text_list").hide();
            $("#list").show();
	} else {
            switch_type=1;
            $("#switch_type").css({"background-position":"-49px"});
            $("#text_list").show();
            $("#list").hide();
	}
        
	$("#switch_type").click(function(){
            console.log('Switch type:'+switch_type);
            if(switch_type==2){
                switch_type=1;
                $("#text_list").show();
                $("#list").hide();
                $("#switch_type").css({"background-position":"0px"});
                document.cookie = "switch=1;expires="+expiryDate;
            }else{
                switch_type=2;
                $("#list").show();
                $("#text_list").hide();
                $("#switch_type").css({"background-position":"-49px"});
                document.cookie = "switch=2;expires="+expiryDate;
            }
	});
        
	
} //



// mini-lightbox
$('#gallery_nav a').lightBox({
       fixedNavigation:false,
       overlayBgColor: '#000',
       overlayOpacity: 0.6,
       imageLoading: 'wp-content/themes/schody/img/top_slides_preloader.gif',
       imageBtnClose: 'wp-content/themes/schody/img/close-trans.png',
       imageBtnPrev: 'wp-content/themes/schody/img/left-trans.png',
       imageBtnNext: 'wp-content/themes/schody/img/right-trans.png',
       containerResizeSpeed: 350,
       txtImage: '',
       txtOf: ''
   });


// zdjecia - alt
$("body").append('<div id="cloud"></div>');
$('#gallery_nav img').mousemove(function(e){
	$('#cloud').text($(this).attr('data-code'));
	$('#cloud').show();
	$('#cloud').css({'top': e.pageY + 5, left: e.pageX + 5});
});

$('#gallery_nav img').mouseout(function(){
	$('#cloud').hide();
});




// mapa - opisy
$("#canvas").hover(function(){
    $("#canvas_cloud").css({opacity: 1});
},function(){
    $("#canvas_cloud").css({opacity: 0});
});


$('#canvas_cloud').append($('#salony').html());

//popup
function ReadCookie(cookieName) {
    var theCookie=""+document.cookie;
    var ind=theCookie.indexOf(cookieName);
    if (ind==-1 || cookieName=="") return ""; 
    var ind1=theCookie.indexOf(';',ind);
    if (ind1==-1) ind1=theCookie.length; 
    return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function showPopup(){
    $("#popup").height(180);
    $("#popup_switch").addClass('popup_switch_on');
}

function hidePopup(){
    $("#popup").height(40);
    $("#popup_switch").removeClass('popup_switch_on');
}

//odczyt ciasteczka
if(ReadCookie('popup')=='false') {
    hidePopup();
}
else{
    showPopup();
}

//icon click
$("#popup_switch").click(function(){
    if (ReadCookie('popup')=='false'){
        showPopup();
        document.cookie = "popup=true";
    }else{
        hidePopup();
        document.cookie = "popup=false";
    }
});

$('#popup > .textwidget').cycle({ 
    fx: 'fade',
    speed:    300, 
    timeout:  5000
});


// end
}); 


$('#gallery_nav > a > img').each(function(){
    $(this).load(function(){
        console.log('lol');
    });
    var width, height, ratio;
    width = $(this).outerWidth();
    height = $(this).outerHeight();
    ratio = width/height;
    if(ratio > 1.33){
        $(this).addClass('wide');
        console.log('szerokokatny');
    }
    console.log(ratio);
});

$(window).load(function(){
    $('#gallery_nav > a > img').each(function(){
        var width, height, ratio;
        width = $(this).outerWidth();
//        console.log('Width:'+width);
        height = $(this).outerHeight();
//        console.log('Height:'+height);
        ratio = width/height;
        if(ratio > 1.33){
            $(this).addClass('wide');
//            console.log('szerokokatny');
        }
//        console.log(ratio);
    });
});




    


