// JavaScript Document

$(document).ready(function () {

    $('.bread-links a:last-child').addClass('currPage');
    $('#txtFirstName').val('First Name');
    $('#txtEmail').val('Email address');

    $('#Name').val('Your Name');
    $('#Email').val('Your email');
    $('#Subject').val('Subject');
    $('#Message').val('Comment');

    $('#commentName').val('Name');
    $('#commentText').val('Comment');

    $('#txtFirstName').focus(function () {
        if ($(this).val() == 'First Name') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('First Name');
        }
    });

    $('#txtEmail').focus(function () {
        if ($(this).val() == 'Email address') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Email address');
        }
    });

    //Update From Pardo 8 June 2011
    $('#Name').focus(function () {
        if ($(this).val() == 'Your Name') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Your Name');
        }
    });

    $('#Email').focus(function () {
        if ($(this).val() == 'Your email') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Your email');
        }
    });

    $('#Subject').focus(function () {
        if ($(this).val() == 'Subject') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Subject');
        }
    });

    $('#Message').focus(function () {
        if ($(this).val() == 'Comment') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Comment');
        }
    });

    $('#commentName').focus(function () {
        if ($(this).val() == 'Name') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Name');
        }
    });

    $('#commentText').focus(function () {
        if ($(this).val() == 'Comment') {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('Comment');
        }
    });
    //End Update

    /*
    $('.leftSubNav li a').click(function () {
        var child = $(this).next('ul');
        if (child.is(':visible')) {
            //alert($(this).next('ul').is(':visible'));
            $(this).next('ul').slideUp();
        } else {
            //alert($(this).next('ul').is(':visible'));
            $(this).next('ul').slideDown();
        }
    });
    */

    ddsmoothmenu.init({
        mainmenuid: "mainMenu", //menu DIV id
        orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
        classname: 'ddsmoothmenu', //class added to menu's outer DIV
        //customtheme: ["#1c5a80", "#18374a"],
        contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
    });


    var currentPosition = 0;
    var slideWidth = 240;
    var slides = $('.newsPagingCont');
    var numberOfSlides = slides.length;

    // Remove scrollbar in JS
    $('#newsWarp').css('overflow', 'hidden');

    // Wrap all .slides with #slideInner div
    slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
	    'float': 'left',
	    'width': slideWidth,
        'z-index': 11000
	});

    // Set #slideInner width equal to total width of all slides
    $('#slideInner').css('width', slideWidth * numberOfSlides);

    // Insert controls in the DOM
    //$('#slideshow')
    //.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    //.append('<span class="control" id="rightControl">Clicking moves right</span>');

    // Hide left arrow control on first load
    manageControls(currentPosition);

    // Create event listeners for .controls clicks
    $('.pagingLink')
    .bind('click', function () {
        // Determine new position
        currentPosition = ($(this).attr('id') == 'rightControl') ? currentPosition + 1 : currentPosition - 1;

        // Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInner').animate({
            'marginLeft': slideWidth * (-currentPosition)
        });
    });

    // manageControls: Hides and Shows controls depending on currentPosition
    function manageControls(position) {
        // Hide left arrow if position is first slide
        if (position == 0) { $('#leftControl').hide() } else { $('#leftControl').show() }
        // Hide right arrow if position is last slide
        if (position == numberOfSlides - 1) { $('#rightControl').hide() } else { $('#rightControl').show() }
    }
});

