/***********************
*  Site Specific JS   *
************************/

//
// Bootsrap Template
//
$(document).ready(function() {
    var elegance = document.createElement('script');
    elegance.type = "text/javascript";
    elegance.src = 'http://cdn.myld.com.au/1/bootstrap/nuro/js/bootstrap.js';
    document.body.appendChild(elegance);

    var carousellib = document.createElement('script');
    carousellib.type = "text/javascript";
    carousellib.src = 'http://cdn.myld.com.au/1/bootstrap/nuro/js/libs/jquery.carouFredSel-5.6.2.js';
    document.body.appendChild(carousellib);

    var tooltip = document.createElement('script');
    tooltip.type = "text/javascript";
    tooltip.src = 'http://cdn.myld.com.au/1/bootstrap/mentor/js/bootstrap/bootstrap-tooltip.js';
    document.body.appendChild(tooltip);

    $('a[rel="tooltip"]').tooltip();

    /*var mentor = document.createElement('script');
        mentor.type = "text/javascript";
        mentor.src = 'http://cdn.myld.com.au/1/bootstrap/mentor/js/mentor.min.js';
        document.body.appendChild(mentor);*/

    var nurocarousel = document.createElement('script');
    nurocarousel.type = "text/javascript";
    nurocarousel.src = 'http://cdn.myld.com.au/1/bootstrap/nuro/js/carousel.js';
    document.body.appendChild(nurocarousel);



    var totop = document.createElement('script');
    totop.type = "text/javascript";
    totop.src = 'http://cdn.myld.com.au/1/bootstrap/nuro/js/toTop.js';
    document.body.appendChild(totop);

    var portfolio = document.createElement('script');
    portfolio.type = "text/javascript";
    portfolio.src = 'http://cdn.myld.com.au/1/js/bootstrap/plugins/bootstrap.portfolio.js';
    document.body.appendChild(portfolio);




    //
    // DOM
    //
    $('header').remove();
    $('footer').remove();

});

$(document).ready(function() {


    $('.carousel').carousel();


});

//form validation 2.0
$(document).ready(function() {
    $('#contact_form').formValidation({ 
      validateText: ["first_name","last_name","phone"],
      validateEmail: ["email_address"],
      validateSpam: true
    }); 
});

//gallery light box

$(document).ready(function() {
    $("a[rel=gallery_group]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        },
        'padding': 1,
        'titleShow': false,
        'overlayOpacity': '0.4',
        'overlayColor': '#333'
    });

    $(".image-link").fancybox();

    $(":input").focus(function() {
        if ($(this).hasClass("needsfilled")) {
            $(this).val("").removeClass("needsfilled");
            $("form label").removeClass("needsfilled");
            $("form select").removeClass("needsfilled2");
        }
    });


    //Dropdown hover
    $('.nav-main li').hover(function() {
        $(this).find('ul').stop(true, true).delay(100).slideDown('fast');
    }, function() {
        $(this).find('ul').stop(true, true).delay(300).slideUp('fast');
    });


    //ACCORDION BUTTON ACTION    


    $('.accordion-heading').click(function() {
        if ($(this).find('.accordion-toggle').hasClass("a-open")) {
            $(this).find('.accordion-toggle').removeClass("a-open");
            $(this).find('i.a_arrow').replaceWith('<i class="icon-chevron-down a_arrow">&nbsp;</i>');
        } else {
            $(this).find('.accordion-toggle').addClass("a-open");
            $(this).find('i.a_arrow').replaceWith('<i class="icon-chevron-up a_arrow">&nbsp;</i>');
        }
    });



    // OUR-SHOWROOM REMAKE
    if (window.location.hash) {

        var hashval = window.location.hash.replace("#", "");

        if ($('.' + hashval).html().length) {

            $('.catNav .selected').removeClass('selected');
            //alert('a[href=#' + hashval + ']');
            $('a[href=#' + hashval + ']').parent().addClass('selected');
            $('.jQload_contents').html($('.' + hashval).html());

        } else {

            // Hash-tag found but its child does not exist. Load default
            $('.catNav .selected').removeClass('selected');
            $('a[href=#kitchens]').parent().addClass('selected');
            $('.jQload_contents').html($('.kitchens').html());

        }

    } else {

        // If no hash-tag on load, load default (.kitchens).

        $('.catNav .selected').removeClass('selected');
        $('a[href=#kitchens]').parent().addClass('selected');

        $('.jQload_contents').html($('.kitchens').html());

    }


    /* NAVIGATION MENU FUNCTIONALITY */
    $('.catNav li a').click(function() {

        $('.jQload_subcontents').slideUp(100);

        // Handle Navigation Menu
        $('.catNav .selected').removeClass('selected');
        $(this).parent().addClass('selected');

        // Handle Content Display

        var tar = $(this).attr('href').replace("#", ""); // This is our "target" DIV where we will grab the HTML from and place in jQload_contents

        $('.jQload_contents').html($('.' + tar).html());
        $('.fancybox').fancybox();

        // PROJECT HANDLING
        $('.xproject-wrapper').click(function() {

            var rel = $(this).attr('rel');

            if (rel.length) {

                var code = $('#' + rel).html();

                if (code.length) {

                    $('.jQload_subcontents').html(code).slideDown(100);
                    $('body,html').animate({
                        scrollTop: 520
                    }, 600);
                    //ATTACH FUNCTIONALITY
                    $('.subClose').click(function() {

                        $('.jQload_subcontents').slideUp(100);

                    });
                    $('.fancybox').fancybox();

                    // Caption Effect for Inner Projects
                    $('.before').add('.after').hover(function() {

                            $(this).children('.xproject-inner-caption').css("opacity", 0);

                        },
                        function() {

                            $(this).children('.xproject-inner-caption').css("opacity", 1);

                        });

                } else {

                    alert(rel + ": Has no HTML");

                }

            } else {
                // Just incase..
                alert("There was an error processing your request. Please report this issue to your webmaster along with any relevant details.");

            }

        });


    });



    /* I hate redundancy but needs to be done */
    $('.xproject-wrapper').click(function() {

        var rel = $(this).attr('rel');

        if (rel.length) {

            var code = $('#' + rel).html();

            if (code.length) {

                $('.jQload_subcontents').html(code).slideDown(100);
                $('body,html').animate({
                    scrollTop: 520
                }, 600);
                //ATTACH FUNCTIONALITY
                $('.subClose').click(function() {

                    $('.jQload_subcontents').slideUp(100);

                });
                $('.fancybox').fancybox();

                // Caption Effect for Inner Projects
                $('.before').add('.after').hover(function() {

                        $(this).children('.xproject-inner-caption').css("opacity", 0);

                    },
                    function() {

                        $(this).children('.xproject-inner-caption').css("opacity", 1);

                    });

            } else {

                alert(rel + ": Has no HTML");

            }

        } else {
            // Just incase..
            alert("There was an error processing your request. Please report this issue to your webmaster along with any relevant details.");

        }

    });

    $('.fancybox').fancybox();

});


// Change branding
$(document).ready(function() {
$('#ld_branding_link').attr('href', 'http://www.localsearch.com.au');
});