
if (typeof console == 'undefined'){
    console = {
        log:function(){},
        warn:function(){}
    }
}

window.select_change = 0;


function checkFlash(){
    var agent = navigator.userAgent.toLowerCase();
    var scrWidth = screen.width;
    var scrHeight = screen.height;
    // The document.documentElement dimensions seem to be identical to
    // the screen dimensions on all the mobile browsers I've tested so far
    var elemWidth = document.documentElement.clientWidth;
    var elemHeight = document.documentElement.clientHeight;
    // We need to eliminate Symbian, Series 60, Windows Mobile and Blackberry
    // browsers for this quick and dirty check. This can be done with the user agent.
    var otherBrowser = (agent.indexOf("series60") != -1) || (agent.indexOf("symbian") != -1) || (agent.indexOf("windows ce") != -1) || (agent.indexOf("blackberry") != -1);
    // If the screen orientation is defined we are in a modern mobile OS
    var mobileOS = typeof orientation != 'undefined' ? true : false;
    // If touch events are defined we are in a modern touch screen OS
    var touchOS = ('ontouchstart' in document.documentElement) ? true : false;
    // iPhone and iPad can be reliably identified with the navigator.platform
    // string, which is currently only available on these devices.
    var iOS = (navigator.platform.indexOf("iPhone") != -1) ||
            (navigator.platform.indexOf("iPad") != -1) ? true : false;
    // If the user agent string contains "android" then it's Android. If it
    // doesn't but it's not another browser, not an iOS device and we're in
    // a mobile and touch OS then we can be 99% certain that it's Android.
    var android = (agent.indexOf("android") != -1) || (!iOS && !otherBrowser && touchOS && mobileOS) ? true : false;


    //if (navigator.platform.match('iPad.*|iPhone.*') || agent.indexOf("android") != -1){
    if (iOS || android || otherBrowser){
        //$("#btop").rotate(10000)
        $(".no-flash").remove();
    } else {
        //$('.ba-top').remove();
    }

}

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s);js.id = id;
  js.src = "//connect.facebook.net/pl_PL/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}
(document, 'script', 'facebook-jssdk'));

try{
    Typekit.load();
}catch(e){}

$(document).ready(function(){
    if ( $.browser.msie && parseInt($.browser.version) == 7) {
        $('ul.menu > li').each(function(){
            var w = $(this).children('ul').width();
            if (w){
                $(this).find('ul li').width(w);
            }
        })
    }
    checkFlash();

	//$("a.iframe").fancybox();
	
	$('a.fancy,img.fancy').fancybox();

    $('a.external').click(function(){
        var cls = $(this).attr('class').split(' ');
        var with_size = false;
        var size = null;
        if (cls.length>1){
            for(var i in cls){
                if (cls[i].match(/ex-size-/)){
                var presize = cls[i].replace('ex-size-','');
                size = presize.split('x');
                with_size = true;
                }
            }
        }
        if (with_size){
            window.open($(this).attr('href'),'','scrollbars=0, width='+size[0]+', height='+size[1]);
        } else {
            window.open($(this).attr('href'));
        }
        return false;
    })
    

    var gray_src;
    $('.to-color').live('mouseover',function(){
        gray_src = this.src;
        this.src = this.src.replace('gray/','');
    })
    $('.to-color').live('mouseout',function(){
        this.src = gray_src;
    })

    $('a.zoom').click(function(){
        $(this).parent().next().find('a:visible:first').trigger('click');
        return false;
    })

    $('.project-gallery').fancybox();

    $('#search_project_button').click(function(){
        $('#search_project_form').submit();
        return false;
    })



    /*
	window.fbAsyncInit = function() {
	FB.init({status: true, cookie: true, xfbml: true});
	};

	(function() {
		var e = document.createElement('script');e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/pl_PL/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());
    
    $('#fb_like_box').hover(function() {
        $(this).stop().animate({right: '0'}, 'slow');
    },
    function() {
        $(this).stop().animate({right: '-237px'}, 'slow');
    }
    );
    */

    $('p.select select').change(function(){
		$(this).css('opacity',0).prev('span').css({
			width:$(this).width()-21,
			height:$(this).height(),
			lineHeight:$(this).height()+'px'
		}).text(  $('option:selected',this).text() )
	}).trigger('change',1)


    
    $('#select_project').change(function(e,a){
        if (a == undefined) $('#search_project_form').submit();
        return false;
    })
    
});

function get_tip(cnt,word)
{
    var r1=cnt % 100;
    if (r1 == 1 && cnt < 100)
    {
    //$p='produkt'; $z='znajduje';
    }
    else
    {
        var r2=r1 % 10;
        if ((r2 > 1 && r2 < 5) && (r1 < 12 || r1 > 14))
        {
            word +='y';
        }
        else
        {
            word += 'ów';
        }
    }
    return word;
}

function changeFontSize(size){
    var ps = $('p');
    $(ps).each(function(p,o){
        $(this).css('font-size',size+'px');
    })
}

function loadView(href,target_id,data){

    var anim = $.Deferred(function( dfd ){
        var l  =1024+($(window).width()-1024)/2
        $('#'+target_id).stop(true).animate({
            left:-l
            },{
            duration:600,
            complete:dfd.resolve
            });
    }).promise();


    var xhr = $.ajax({
        url:href,
        type:'post',
        dataType:'json',
        data: data
    });


    $.when(xhr,anim).then(function(args){

        var l  =1024+($(window).width()-1024)/2;
        $('#main').css('overflow','hidden')
        $('#'+target_id).css('left',l).animate({
            left:0
        },{
            duration:600,
            complete:function(){

                $('#'+target_id).css('overflow','visible')

            }
        });
        renderView(args[0],target_id)
    })

}

function renderView(data,target_id){
    $('#'+target_id).html(data.content)
}

function formReset(form_id){
  $(':input','#'+form_id)
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');

}

$(document).ready(function(){
    var totale = $('#packages').children('li').size();
    var first_package = Math.floor((totale / 2) - 2);
    if (totale > 2){
        $("div.packages").jCarouselLite({
            btnNext: ".slide-right",
            btnPrev: ".slide-left",
            circular: false,
            visible: 4,
            start: first_package,
            afterEnd: function(a) {
            }
        });
        if (totale > 4){
            $('.packages-button').show();
        }
    } else {
        //$('li.package div').addClass('ofe');
        $(".packages-wrap").addClass('packages-wrap2');
        $(".packages-wrap").removeClass('packages-wrap');
        $(".packages").addClass('packages2');
        $(".packages").removeClass('packages');
    }

	$("a.fbox").fancybox({
        type: 'ajax',
        width: 460,
        height: 800,
        overlayColor: 'white',
        padding: 0,
        onComplete: function() {
            $("#fancybox-close").addClass('fast_internet fbox_close');
        }
    });

    $("a.calc").fancybox({
//    type: 'swf',
    width: 975,
    height: 930,
    overlayColor: 'white',
    padding: 0,
    scrolling: 'no',
    onComplete: function() {
        $('#fancybox-content').css('height',930);
        $('#fancybox-overlay').css('height',$(document).height());
        $("#fancybox-close").addClass('fast_internet fbox_close');
    }


});

});
