$(document).ready(function(){
    $('#offers').equalHeights();

    $("a[rel='gallery']").colorbox({opacity: 0.5, transition:"fade"});
    $("ul#gallery li:nth-child(4n)").addClass('last');

    $("ul#gallery li a").each( function(){
       $(this).prepend('<span></span>', '<div class="galleryOverlay"></div>');
    });
    $('div.galleryOverlay').fadeOut();
    $("ul#gallery li a span").hover( function(){
        $(this).animate({ width: 203, height: 118, top: 0, left: 0}, 120);
        $(this).parent().find('.galleryOverlay').fadeIn(120);
        $(this).parent().find('img').animate({ marginRight: 6, marginTop: 6}, 120);
    }, function(){
        $(this).animate({ width: 215, height: 130, top: -6, left: -6 }, 120);
        $(this).parent().find('.galleryOverlay').fadeOut(120);
        $(this).parent().find('img').animate({ marginRight: 0, marginTop: 0}, 120);
    });

    $("form#contact").validate();

    // $("a#quickCall").colorbox({width:"420px", inline:true, href:"#quick", opacity: 0.5});
    // $("a#funCall").colorbox({width:"420px", inline:true, href:"#fun", opacity: 0.5});
    // $("a#proCall").colorbox({width:"420px", inline:true, href:"#pro", opacity: 0.5});

    $("a#quickCall").colorbox({iframe:true, innerWidth:400, innerHeight: 300, opacity: 0.5});
    $("a#funCall").colorbox({iframe:true, innerWidth:400, innerHeight: 300, opacity: 0.5});
    $("a#proCall").colorbox({iframe:true, innerWidth:400, innerHeight: 300, opacity: 0.5});

    $('#main').after('<div id="mainClose"></div>');

    $('.fieldHolder, .textHolder').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });
    $('.fieldHolder input, .textHolder textarea').focus(function () {
        $(this).parent().addClass('focus');
    }).blur(function () {
        $(this).parent().removeClass('focus');
    });

    // $("#quick form").validate();
    // $("#pro form").validate();
    // $("#fun form").validate();

    /* Custom combo box hover behaviour */
    $(".customComboHolder select").each( function(){
       $(this).siblings("div").html($(this).find(":selected").text());
    });
    $(".customComboHolder select").hover(
        function () {$(this).parent().addClass("dropdown_over");},
        function () {$(this).parent().removeClass("dropdown_over");}
    );
    $(".customComboHolder select").change(function() {
        $(this).siblings("div").html($(this).find(":selected").text());

    });

});
function slideHeight(curr, next, opts, fwd){
        var $ht = $(this).height();
        $(this).parent().animate({
            height: $ht-5
        }, 260);
}

function slideNo(curr,next,opts) {
    var caption = 'Slika ' + (opts.currSlide + 1) + ' od ' + opts.slideCount;
    $('#slideNo').html(caption);
}

$.fn.equalHeights = function(px) {
    $(this).each(function(){
        var currentTallest = 0;
        $(this).children().each(function(i){
            if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        });
        if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
        $(this).children().css({'min-height': currentTallest+50});
    });
    return this;
};
Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
    //set defaults
    settings = jQuery.extend({
        scope: 'body',
        reverse: false
    }, settings);

    var pxVal = (this == '') ? 0 : parseFloat(this);
    var scopeVal;
    var getWindowWidth = function(){
        var de = document.documentElement;
        return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    };

    if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
        var calcFontSize = function(){
            return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
        };
        scopeVal = calcFontSize();
    }
    else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };

    var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
    return result;
};
