﻿jQuery(window).load(function() {
    new ImageSelector();
    jQuery('#SubmitVideo').click(function() {
        jQuery('#uploadingVideo').css('display', 'block');
    });
    
    jQuery('#NewsArchiveList > li').children('a').click(function(e) {
        e.preventDefault();
        if (jQuery(this).parent().children('ul').hasClass('hide')) {
            jQuery(this).parent().children('ul').removeClass('hide');
        }
        else {
            jQuery(this).parent().children('ul').addClass('hide');
        }
    });

    jQuery('div.headlines ul li a.arrow').each(function(i) {
        jQuery(this).click(function(e) {
            e.preventDefault();
            if (jQuery(this).parent().next().hasClass('hide'))
                jQuery(this).parent().next().slideDown(500, function() {
                    jQuery(this).removeClass('hide');
                });
            else
                jQuery(this).parent().next().slideUp(500, function() {
                    jQuery(this).addClass('hide');
                });
        });
    });
});

function ImageSelector(){

    this.init = function(){
        var self = this;
        this.imgArray = new Array();
        this.images = jQuery('div.columnBody img');
        this.images.each(function(i){
            self.imgArray[i] = jQuery(this);
        });
        this.images.each(function(i){
            jQuery(this).click(function(e){
                e.preventDefault();
                for(j=0;j<self.imgArray.length;j++){
                    if (self.imgArray[j].hasClass('selected'))
                        self.imgArray[j].removeClass('selected');
                }
                jQuery(this).addClass('selected');
                jQuery('#selectedImage').val(jQuery(this).attr('id'));
            });
        });
    }

    this.init();
}

$().ready(function() {
    var obj = document.getElementById("myMedia");
    $("div#audiolist h2 a").click(function() {
        obj.URL = $(this).attr("href");
        obj.controls.play();
        return false;
    });

    $('div.videolist a').click(function() {
        var self = $(this);
        $('div#Media-0 .mediaItem a').each(function() {
            if (self.attr('href') == $(this).attr('href'))
                $(this).click();
        });
        return false;
    });


    $('div.videolist a').click(function() {
        var self = $(this);
        $('div#Media-2 .mediaItem a').each(function() {
            if (self.attr('href') == $(this).attr('href'))
                $(this).click();
        });
        return false;
    });
    
    $('div.audiolist a').click(function() {
        var self = $(this);
        $('div#Media-1 .mediaItem a.playaudio').each(function() {
            if (self.attr('href') == $(this).attr('href'))
                $(this).click();
        });
        return false;
    });

    $('div#videolist a').click(function() {
        var self = $(this);
        $('div#Media-0 .mediaItem a').each(function() {
            if (self.attr('href') == $(this).attr('href'))
                $(this).click();
        });
        return false;
    });

    
});

