//JQUERY Settings

jQuery(document).ready(function() {

    //pokreni head galeriju
    jQuery('#head_gallery_imgs').cycle({
        fx: 'fade',
        speed: 1200,
        timeout: 5000, //5000
        pager: '#head_nav .numbers'
        //next: '#gal_next',
        //prev: '#gal_prev'
    });

    jQuery('#youtube_list').cycle({
        fx: 'fade',
        speed: 1200,
        timeout: 5000,
        pager: '#youtube_nav'
        //next: '#gal_next',
        //prev: '#gal_prev'
    });

    jQuery("ul.gallery").prettyGallery({
        itemsPerPage: 6,
        of_label: ' / ' /* The content in the page "1 of 2" */
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: true, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
        callback: function() { }
    });


    //makni prvu crtu na lijevoj listi
    jQuery('.left_box_list3 ul li:first').css({ background: 'none' });
    jQuery('.left_box_dogadjaji3 ul li:last').css({ background: 'none' }).find("a").css({ paddingBottom: '0' });

    //pokreni main menu
    //$("ul.sf-menu").superfish({ 
    //        pathClass:  'current'
    //    });

    jQuery("#page_mail").click(function() {
        $("html").scrollTo({ top: '0px', left: '0px' }, 500, { onAfter: function() {
            jQuery("#sendtofriend").slideToggle("slow");
        }
        });

        return false;
    });

    jQuery("#sendtofriend_close1").click(function() {
        jQuery("#sendtofriend").slideToggle("slow");
        return false;
    });

    //objekt tabovi
    var vrijednostObjektTaba;
    jQuery("#content_objekt_tab1 a, #content_objekt_tab2 a, #content_objekt_tab3 a").click(function() {
        jQuery("#content_objekt_tab1 a, #content_objekt_tab2 a, #content_objekt_tab3 a").removeClass("content_objekt_tab_active");
        jQuery(this).addClass("content_objekt_tab_active");
        vrijednostTaba = jQuery(this).attr('rel');
        jQuery('#objekt_tab3, #objekt_tab2, #objekt_tab1').css({ display: 'none' });
        jQuery("#" + vrijednostTaba).css({ display: 'block' });
    });
    //dodaj kraj na zadnji tab
    // jQuery(".content_objekt_box_line2 ul li:last").addClass("content_objekt_tab_last");

    jQuery("#objekt_tab2,#objekt_tab3").css({ display: 'none' });

    // Reset Font Size
    var originalFontSize = $('body').css('font-size');
    $(".resetFont").click(function() {
        $('body').css('font-size', originalFontSize);
    });
    // Increase Font Size
    $("#page_plus").click(function() {
        //var currentFontSize = $('.content_objekt_box2, .content_box2').css('font-size');
        //var currentFontSizeNum = parseFloat(currentFontSize, 10);
        //var newFontSize = currentFontSizeNum*1.2;
        $('.content_objekt_box2, .content_box2').css('font-size', '1.2em');
        return false;
    });
    // Decrease Font Size
    $("#page_minus").click(function() {
        //var currentFontSize = $('.content_objekt_box2, .content_box2').css('font-size');
        //var currentFontSizeNum = parseFloat(currentFontSize, 10);
        //var newFontSize = currentFontSizeNum*0.85;
        $('.content_objekt_box2, .content_box2').css('font-size', '1em');
        return false;
    });

    //SendToFriend
    var bojaErrora = "#ff0000";
    $("#sendtofriend_submit").click(function() {
        $(".error").hide();
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var sendEmailPosiljateljaVal = $("#sendEmailPosiljatelja").val();
        if (sendEmailPosiljateljaVal == '') {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        } else if (!emailReg.test(sendEmailPosiljateljaVal)) {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        }


        var sendEmailPrimateljaVal = $("#sendEmailPrimatelja").val();
        if (sendEmailPrimateljaVal == '') {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        } else if (!emailReg.test(sendEmailPrimateljaVal)) {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        }


        var sendImePosiljateljaVal = $("#sendImePosiljatelja").val();
        if (sendImePosiljateljaVal == '') {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        }


        var sendEmailPorukaVal = $("#sendEmailPoruka").val();
        if (sendEmailPorukaVal == '') {
            $("span.alert").css({ color: bojaErrora });
            hasError = true;
        }



        if (hasError == false) {

            $("p.sendtofriendButton").append("<img class='loadingImg' src='../images/loading2.gif' alt='Loading' id='loading' />");

            $.post("sendFriend.aspx",
   				{ sendEmailPosiljatelja: sendEmailPosiljateljaVal, sendEmailPrimatelja: sendEmailPrimateljaVal, sendImePosiljatelja: sendImePosiljateljaVal, sendEmailPoruka: sendEmailPorukaVal },
   					function(data) {
   					    $("img.loadingImg").hide();
   					    $("p.sendtofriendSent").append('<img src="../images/mailsent2.png" alt="" id="" />');
   					    $("p.sendtofriendSent").animate({ opacity: 1.0 }, 1500)
   					    $("p.sendtofriendSent").fadeOut('fast', function() {

   					        $("#sendtofriend").slideToggle("slow");
   					        pobrisiSendToFriendFormu();
   					    });
   					}
				 );

        }
        return false;
    });

    //SendToFriend END
    if (window.location.hash == "#res") {
        $("#content_objekt_tab3").find("a").click();
    }

    $("#interesi_home li,#head_nav,.hot_deals,#sub_footer,.left_box_dogadjaji, .banners, .banners a,.hot_deals_list_sort, .full_content, .interesi_content, .search_content, .banners_vrijeme, .footer_facebook, .footer_youtube,ul.ostali_objekti,.banners_newsletter").corner("5px");

    $("#interesi_home li, .hot_deals ul li, li.head_slide_box").click(function() {
        window.open($(this).find("a").attr("href"), "_top");
    });
    $(".hot_delas_list_left").click(function() {
        window.open($(this).find("h2 a").attr("href"), "_top");
    });

    $(".hot_deals ul li:last").addClass("last");
    //$(".hot_deals_list ul").find("li:last").css({ borderBottom: '0 none' });

    $("#tempDanas").html($("#today_temperatura").val());
    

    //SEARCH INPUT
    var labelTxt = $('.head_search input').attr('value');
    $('.head_search input').focus(function() {
        if ((this.value == '') || (this.value == labelTxt)) {
            $(this).val('');
            $(this).css({ background: "#f5fafd" });
        }
    });
    $('.head_search input').blur(function() {
        if (this.value == '') {
            $(this).val(labelTxt);
            $(this).css({ background: "#e5f3fc" });
        }
    });
    $('.head_search input').keypress(function(event) {
        if (event.keyCode == '13') {
            var labelTxt = $('.head_search input').attr('value');
            if (labelTxt == '') { $(this).css({ background: '#ffdbd5' }); }
            else {
                window.open("search.aspx?search=" + labelTxt, "_top");
            }

        }
    });

    $(".head_slide_box a").css({opacity:'0.9'});

    //kraj
});

