var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
var IE8 = (navigator.userAgent.indexOf("MSIE 8")>=0) ? true : false;

if(IE6){
	$(function(){		
			window.location = 'ie6.html';		
	});		
}

$(function () {	
			
	set_left_menu();
	
	$(document).delegate('a.left_menu_item', 'click', function () {
		$('.hp_cont').css('background', 'none');
        $('a.left_menu_item').removeClass('sel');
        $(this).addClass('sel');
        $('.top_nav').find('a').removeClass('sel');
        var the_artist = $(this).html();
        set_artist(the_artist);
    });
	
	$(document).delegate('a.vid_thumb', 'click', function () {
        var the_id = $(this).attr('id');
        var the_artist = $(this).find('span').html();
		$('.hp_cont').css('background', 'none');
        set_big_vid(the_id, the_artist);																
    });
	
});


var xml_souce = 'xml/settings.xml';

function set_left_menu() {

    $('#left_nav ul').hide();

    $('<div id="preload_menu"></div>').html('<img src="img/menu-loader.gif" alt="loading data..." />').prependTo($('#left_nav'));


    var link_list;

    $.ajax({
        type: 'GET',
        url: xml_souce,
        dataType: 'xml',
        complete: function (data) {

            var json = $.xmlToJSON(data.responseXML);

            $('#preload_menu').remove();
            $('#left_nav ul').fadeIn('slow');

            for (var x = 0; x < json.left_menu[0].item.length; x++) {
                var in_left_nav = json.left_menu[0].item[x].in_left_nav;
                if (in_left_nav == 'yes') {
                    var menu_img = json.left_menu[0].item[x].menu_img[0].Text;
                    var item_name = json.left_menu[0].item[x].name;
                    link_list = '<li><a href="#1" class="left_menu_item" style="background-image:url(img/' + menu_img + ')">' + item_name + '</a></li>';
                    $(link_list).appendTo($('#left_nav ul'));
                }
            }
			
			link_manymore = '<li><a href="all_videos.html" class="left_menu_item many_more">and MANY MORE</a></li>';
			$(link_manymore).appendTo($('#left_nav ul'));
        }
    });

}

function set_artist(the_artist) {

    $('.main_box').empty();
	$('<div class="hp_cont">').appendTo($('.main_box'));		
	$('.hp_cont').hide();
	$('<div class="big_thumb_box">').appendTo($('.hp_cont'));
	$('<div class="small_thumb_box">').appendTo($('.hp_cont'));
    $('<div id="preload_videos" style="text-align:center;margin-top:150px;"></div>').html('<img src="img/main_loader.gif" alt="loading data..." />').prependTo($('.hp_cont'));

    var thumb_list;
    var thumb_big;

    $.ajax({
        type: 'GET',
        url: xml_souce,
        dataType: 'xml',
        complete: function (data) {

            var json = $.xmlToJSON(data.responseXML);

            $('#preload_videos').remove();
			
			$('.hp_cont').css('background', 'url(img/big_thumb_desc_frame.png) no-repeat right top');

            var x = 0;

            for (var y = 0; y < json.videos[0].video.length; y++) {

                var the_one = json.videos[0].video[y].artist;


                if (the_one == the_artist) {

                    var item_id = json.videos[0].video[y].id;
                    var item_title = json.videos[0].video[y].title;

                    if (x == 0) {
                        var item_long_desc = json.videos[0].video[y].Text;
                        thumb_big = '<div class="pic_box"><strong class="tit">' + the_one + '</strong>';
                        thumb_big += '<div id="vid_box"></div>';
                        thumb_big += '</div><div class="desc_box">';
                        thumb_big += '<strong class="desc_tit"><span id="tit1">' + the_one + '</span><br />';
                        thumb_big += '"<span id="tit2">' + item_title + '</span>"</strong>';
                        thumb_big += '<div class="desc_txt" id="desc_txt">' + item_long_desc + '</div>';
                        thumb_big += '</div>';
                        $(thumb_big).appendTo($('.big_thumb_box'));
                        $('#vid_box').youTubeEmbed({
                            video: 'http://www.youtube.com/watch?v=' + item_id,
                            width: 384,
                            progressBar: true
                        });
                    }
                    if (x > 0 && x < 4) {
                        thumb_list = '<div class="thumb">';
                        thumb_list += '<a href="#1" class="vid_thumb" id="' + item_id + '"><img src="' + $.jYoutube('http://www.youtube.com/watch?v=' + item_id, 'small') + '" alt="" class="pic" /><span style="display:none;">' + the_one + '</span></a>';
                        thumb_list += '<strong class="thumb_tit">' + the_one + '</strong>';
                        thumb_list += '<strong class="thumb_desc">' + item_title + '</strong>';
                        thumb_list += '</div>';
                        $(thumb_list).appendTo($('.small_thumb_box'));

                    }
                    x++;
                }
				
				$('.hp_cont').fadeIn('slow');
            }

        }
    });

}

function set_big_vid(the_id, the_artist) {

    $.ajax({
        type: 'GET',
        url: xml_souce,
        dataType: 'xml',
        complete: function (data) {

            var json = $.xmlToJSON(data.responseXML);

            $('#vid_box').empty();
            $('.small_thumb_box').empty();
			
			$('.hp_cont').hide().css('background', 'url(img/big_thumb_desc_frame.png) no-repeat right top');

            var x = 0;

            for (var y = 0; y < json.videos[0].video.length; y++) {

                var item_id = json.videos[0].video[y].id;
                var item_title = json.videos[0].video[y].title;
                var item_aut = json.videos[0].video[y].artist;

                if (item_aut == the_artist && json.videos[0].video[y].id != the_id && x < 3) {
                    thumb_list = '<div class="thumb">';
                    thumb_list += '<a href="#1" class="vid_thumb" id="' + item_id + '"><img src="' + $.jYoutube('http://www.youtube.com/watch?v=' + item_id, 'small') + '" alt="" class="pic" /><span style="display:none;">' + item_aut + '</span></a>';
                    thumb_list += '<strong class="thumb_tit">' + item_aut + '</strong>';
                    thumb_list += '<strong class="thumb_desc">' + item_title + '</strong>';
                    thumb_list += '</div>';
                    $(thumb_list).appendTo($('.small_thumb_box'));
                    x++;
                }

                if (json.videos[0].video[y].id == the_id) {
                    var video_title = json.videos[0].video[y].title;
                    var item_long_desc = json.videos[0].video[y].Text;

                    $('#vid_box').youTubeEmbed({
                        video: 'http://www.youtube.com/watch?v=' + the_id,
                        width: 384,
                        progressBar: true
                    });
                    $('#tit1').empty().html(item_aut);
                    $('#tit2').empty().html(video_title);
                    $('#desc_txt').empty().html(item_long_desc);
                }

            }
			$('.hp_cont').fadeIn('slow');
        }
    });

    return false;
	
}

