$(document).ready(function() {

    // ADD CLASS FOR JAVASCRIPT CLIENTS
    $('body').addClass('jq');

    // ROUND CORNERS ON IMAGES
    $('img.rounded').wrap(function() {
        return '<p class="imgRound" style="background-image: url(' + $(this).attr("src") + '); " />';
    });


    /* No anim om logo 
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { 
    setTimeout('fadeRandomC2()',5000);
    } else {
    setTimeout('fadeRandomC()',5000);
    }
    */

    //setTimeout('randomC()', 8000);
    $('#logo .c ul').innerfade({ animationtype: 'fade', speed: 2000, timeout: 8000, type: 'sequence', containerheight: 'auto' });

    $('.navblock li a').click(function() {
        $('.navblock li').removeClass('akt');
        $(this).parent('li').addClass('akt');
    });


    $('.navblock li.more a').removeAttr('href');


    var loaderImg = $('<img />').attr('src', 'Web/Core/UI/Skins/Mobile_Default/Images/ajax-loader.gif');
    $('.navblock li.more').click(function() {
        $thisLI = $(this);
        // Simulate AJAX so user sees what happens
        $(this).removeClass('akt').html(loaderImg);
        $(this).parents('ul').children('li.hidden').delay(400).slideDown(300, function() {
            $thisLI.fadeOut(300, function() {
                $thisLI.remove();
            }).removeClass('hidden');
        });
    });



    $('.navblock ul.applyeffect').each(function() {
        $(this).children('li:first').children('a').toggleClass('mini');
        origHeight = $(this).height();
        $(this).animate({
            height: '20px'
        }, 0, function() {
            $(this).children('li:not(:first-child)').hide();
            $(this).children('li:first-child').addClass('last');
            $(this).attr('id', 'h' + origHeight);
        });

    });



    $('.navblock li:first-child').click(function() {
        $(this).children('a').toggleClass('mini');
        $thisUL = $(this).parents('ul');
        origHeight = $thisUL.height();
        if ($(this).children('a').hasClass('mini')) {
            $thisUL.animate({
                height: '20px'
            }, function() {
                $thisUL.children('li:not(:first-child)').hide();
                $thisUL.children('li:first-child').addClass('last');
                $thisUL.attr('id', 'h' + origHeight);
            });
        } else {
            $thisUL.children('li:not(.hidden)').show();
            if ($thisUL.attr('id') != "") {
                origHeight = $thisUL.attr('id').replace('h', '') + 'px';
            } else {
                origHeight = '100%';
            }
            $thisUL.animate({
                height: origHeight
            }, function() {
                $thisUL.children('li:first-child').removeClass('last');
                $thisUL.removeAttr('id').removeAttr('style');
            });
        }
    });


    contactWidth = $('.contactnav').width() + 10;
    $('.contactnav').css('width', contactWidth + 'px');
    $('#contact').css('width', '35px');

    $('#contact a.button').removeAttr('href');

    $('#contact a.button').click(function(e) {
        e.preventDefault();
        if ($('#contact').width() < contactWidth) {
            animTo = contactWidth + $('#contact a.button').width() + 20;
        } else {
            animTo = 35;
        }

        $('#contact').animate({
            width: animTo + 'px'
        });

    });



    shareWidth = $('.sharenav').width() + 0;
    $('.sharenav').css('width', shareWidth + 'px');
    $('#share').css('width', '41px');

    $('#share a.button').removeAttr('href');

    $('#share a.button').click(function(e) {
        e.preventDefault();
        if ($('#share').width() < shareWidth) {
            animTo = shareWidth + $('#share a.button').width();
        } else {
            animTo = 41;
        }

        $('#share').animate({
            width: animTo + 'px'
        });

    });



    $('.navblock li:first-child').addClass('first').next().addClass('second');







    // GET RID OF BROWSER BAR / IPHONE/TOUCH
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        setTimeout(function() { window.scrollTo(0, 1); }, 100);
    }



    window.onorientationchange = updateOrientation;
    window.onload = updateOrientation;


    /* updateOrientation checks the current orientation, sets the body's class attribute to portrait, landscapeLeft, or landscapeRight, 
    and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events".  */
    function updateOrientation() {
        /*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
        left, or landscape mode with the screen turned to the right. */
        var orientation = window.orientation;
        switch (orientation) {

            case 0:
                /* If in portrait mode, sets the body's class attribute to portrait. Consequently, all style definitions matching the body[class="portrait"] declaration
                in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
                //document.body.setAttribute("class","portrait");
                $('body').toggleClass('portrait').removeClass('landscape');
                break;

            case 90:
                /* If in landscape mode with the screen turned to the left, sets the body's class attribute to landscapeLeft. In this case, all style definitions matching the
                body[class="landscapeLeft"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
                //document.body.setAttribute("class","landscape left");
                $('body').toggleClass('landscape').removeClass('portrait');
                break;

            case -90:
                /* If in landscape mode with the screen turned to the right, sets the body's class attribute to landscapeRight. Here, all style definitions matching the 
                body[class="landscapeRight"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
                //document.body.setAttribute("class","landscape right");
                $('body').toggleClass('landscape').removeClass('portrait');
                break;

            case 180:
                /* If in landscape mode with the screen turned to the right, sets the body's class attribute to landscapeRight. Here, all style definitions matching the 
                body[class="landscapeRight"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
                //document.body.setAttribute("class","bottom");				
                $('body').toggleClass('landscape');
                break;
        }

    }



});


