jQuery.fn.exists = function(){return jQuery(this).length>0;}


$(document).ready(function () {

    //jQuery Tools - Overlay
    if ($('a[rel]').exists()) {
        $('a[rel]').overlay({ mask: '#3f3f3f' });
    }

    $(function () {
        // bind change event to select
        $('a.zoom-in').bind('click', function () {
            var url = $(this).attr('href'); // get selected value
            $('#largeImage').attr('src', url);
            return false;
            //alert($('#large').html());
            //alert($('#ctl00_cphMainContent_largeImage').attr('src'));
        });
    });



    // setup ul.tabs to work as tabs for each div directly under div.panes
    if ($("ul.tabs").exists()) {
        $("ul.tabs").tabs("div.panes > div");
    }
    if ($("ul.tabs2").exists()) {
        $("ul.tabs2").tabs("div.panes2 > div");
    }
    // color every other table row
    $('table#itemize tbody tr:odd').addClass('odd');

    // jQuery Cycle
    if ($("#myslides").exists()) {
        $('#myslides')
	.cycle({
	    fx: 'scrollHorz', // choose your transition type
	    timeout: 0, // specifies how many milliseconds will elapse between the start of each transition
	    pause: 1, // so that pauses when user hovers over a slide
	    prev: '.prev', // use CSS to style
	    next: '.next', // use CSS to style
	    cleartypeNoBg: true  // clear background for ie
	}); // every child element of the container becomes a slide 	
    }
    if ($("#myslides2").exists()) {

        $('#myslides2')
	.cycle({
	    fx: 'scrollHorz', // choose your transition type
	    timeout: 0, // specifies how many milliseconds will elapse between the start of each transition
	    pause: 1, // so that pauses when user hovers over a slide
	    prev: '.prev2', // use CSS to style
	    next: '.next2', // use CSS to style
	    cleartypeNoBg: true  // clear background for ie
	}); // every child element of the container becomes a slide 	
    }
    if ($("#myslides3").exists()) {

        $('#myslides3')
	.cycle({
	    fx: 'scrollHorz', // choose your transition type
	    timeout: 0, // specifies how many milliseconds will elapse between the start of each transition
	    pause: 1, // so that pauses when user hovers over a slide
	    prev: '.prev3', // use CSS to style
	    next: '.next3', // use CSS to style
	    cleartypeNoBg: true  // clear background for ie
	}); // every child element of the container becomes a slide 	
        // end jQuery Cycle	
    }


    //tabs - tabs MUST come AFTER the jQuery Cycle above or WILL NOT work properly due to hiding
    if ($(".read-more").exists()) {
        $('.tabs-container').readmoretabs(260);
    }
    if ($(".read-more-tabs").exists()) {
        $('.top-box').readmore(117);
    }



    /*Sort Tabs*/

    $(function () {
        var tabContainers = $('div.cont > table');
        tabContainers.hide().filter(':first').show();

        $('#sort-bar a').click(function () {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('#sort-bar a').removeClass('selected');
            $(this).addClass('selected');
            return false;
        }).filter(':first').click();
    });


    $(function () {
        // bind change event to select
        $('#jump-to').bind('change', function () {
            var url = $(this).val(); // get selected value
            if (url) { // require a URL
                window.location = url; // redirect
            }
            return false;
        });
    });

});
