$(document).ready(function () {


    /*-------------------------------------------    
    Open external links in a new window
    -------------------------------------------*/
    $("a[rel='external']").click(function () {
        window.open($(this).attr('href'));
        return false;
    });



    /* HOVER INTENT */
    function megaHoverOver() {
        $(this).find(".sub, .sub#last").stop().show();

        //Calculate width of all ul's
        (function ($) {
            jQuery.fn.calcSubWidth = function () {
                rowWidth = 0;
                //Calculate row
                $(this).find("ul").each(function () {
                    rowWidth += $(this).width();
                });
            };
        })(jQuery);

        if ($(this).find(".row").length > 0) { //If row exists...
            var biggestRow = 0;
            //Calculate each row
            $(this).find(".row").each(function () {
                $(this).calcSubWidth();
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            //Set width
            //$(this).find(".sub, sub#last").css({'width' :biggestRow});
            //$(this).find(".row:last").css({'margin':'0'});

        } else { //If row does not exist...

            $(this).calcSubWidth();
            //Set Width
            $(this).find(".sub").css({ 'width': rowWidth });

        }
    }

    function megaHoverOut() {
        $(this).find(".sub").stop().hide();
    }


    var config = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)    
        interval: 0, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 0, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    //$("ul#topnav li .sub").css({'opacity':'0'});
    $("ul#topnav li").hoverIntent(config);


    // FANCY BOX ///////////////////////
    /* This is basic - uses default settings */

    $("a.img_zoom").fancybox();

    /* Using custom settings */

    $("a.img_zoom").fancybox({
        'titleShow': true, /*Changed by JH - orig false*/
        'titlePosition': 'inside', /*Added by JH */
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 'fast',
        'speedOut': 'fast'

    });


    $("a.video_zoom_window").click(function () {
        $.fancybox({
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 'fast',
            'speedOut': 'fast',
            'width': 676,
            'height': 405,
            'title': this.title,
            'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type': 'swf',
            'swf': {
                'wmode': 'window',
                'allowfullscreen': 'true'
            }
        });
        return false;
    });

    $("a.video_zoom").click(function () {
        $.fancybox({
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 'fast',
            'speedOut': 'fast',
            'width': 676,
            'height': 405,
            'title': this.title,
            'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type': 'swf',
            'swf': {
                'wmode': 'transparent',
                'allowfullscreen': 'true'
            }
        });
        return false;
    });


     /* This enables another page to 'popup'. Just add class="iframe" to anchor tag */
   $(document).ready(function(){
    $("a.iframe").fancybox({
		     'width' : '75%',
		     'height' : '75%',
		     'autoScale' : false,
		     'transitionIn' : 'none',
		     'transitionOut' : 'none',
		     'type' : 'iframe'
	     });
     });


    /// SHOW MORE SHOW LESS ////////////////////



    $('a.reveal').toggle(function () {
        $(this).parent().find('.more_info').slideDown();
        $(this).html('- Less');
    },
		function () {
		    $(this).parent().find('.more_info').slideUp();
		    $(this).html('+ More')
		});
    /* function() { 
    $('.more_info').slideDown(); 
    $(this).html('- Less');
    }, 
    function() { 
    $('.more_info').slideUp(); 
    $(this).html('+ More');
    }  */




    // MAIN IMAGE SLIDER //////////////////////////////////

    //Show Banner
    $(".main_image .desc").show(); //Show Banner
    $(".main_image .block").animate({ opacity: 0.8 }, 1); //Set Opacity

    //Click and Hover events for thumbnail list
    $(".image_thumb ul li:first").addClass('active');
    $(".image_thumb ul li").hover(function () {
        //Set Variables
        var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
        var imgTitle = $(this).find('.imgloc').attr("href"); //Get Main Image URL
        var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
        var imgDescHeight = $(".main_image").find('.block').height(); //Calculate height of block	

        if ($(this).is(".active")) {  //If it's already active, then...
            return false; // Don't click through
        } else {
            //Animate the Teaser				

            $(".main_image .block").show().html(imgDesc); $(".main_image img").attr({ src: imgTitle, alt: imgAlt });
        }

        $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
        $(this).addClass('active');  //add class of 'active' on this list only
        return false;

    }).hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });


    //Toggle Teaser
    //	$("a.collapse").click(function(){
    //		$(".main_image .block").slideToggle();
    //		$("a.collapse").toggleClass("show");
    //	});

    var swap_text_boxes = [];

    function init_swap_text_boxes() {
        //Store the default value for each box
        $('input[type=text][value].swaptextbox').each(function () {
            swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
        });
        //Add focus and blur events to set or clear the value
        $('input[type=text][value].swaptextbox').bind('focus', function () {
            if ($(this).val() == swap_text_boxes[$(this).attr('id')]) {
                $(this).val('');
            }
        });
        $('input[type=text][value].swaptextbox').bind('blur', function () {
            if ($(this).val() == '') {
                $(this).val(swap_text_boxes[$(this).attr('id')]);
            }
        });
    }

    $(document).ready(function () { init_swap_text_boxes(); });






});



/* IE 6 HOVER FIX */

(function ($) {
    $(document).ready(function () {
        $.single = function (a) { return function (b) { a[0] = b; return a } } ($([1]));
        /*@cc_on
        if (!window.XMLHttpRequest) {
            $('.hoverable').each(function () {
                this.attachEvent('onmouseenter', function (evt) { $.single(evt.srcElement).addClass('hovered'); });
                this.attachEvent('onmouseleave', function (evt) { $.single(evt.srcElement).removeClass('hovered'); });
            });
        }
        @*/
    });
} (jQuery));

window.onload = function () {
    $("tr:nth-child(even)").addClass("even");
};
	

	
	


