/*************** START BASE SITE FUNCTIONS  *********************/


function passwordPopup() {
    window.open("/yoursay/forgotpassword", "c365forgotPass", "width=550,height=480,statusbar=no,scrollbars=no,resize=no");
}

function registerPopup() {
    window.open("/yoursay/register", "c365Reg", "width=870,height=580,statusbar=no,scrollbars=yes,resize=yes");
}

function emailArticlePopup(url) {
    window.open(url, "c365Email", "width=550,height=500,resizable=yes,scrollbars=yes'");
}
/* tab box function */
tabs=function(p){

    // check if any of the tabs have tabs-selected class - if not default to the first one
    if ($(p+" .anchors li.tabs-selected").length == 0) {
        $(p+" .anchors li:first").addClass('tabs-selected');
    }
    $(p+" .anchors li").click(function(){
        $(this).parents('.anchors').find('li').removeClass('tabs-selected');
        $(this).addClass('tabs-selected');
        var tablink=$(this).find('a').attr('href');
        tablink=tablink.split('#')[1];
        $(this).parents('.ms-tabs').find("div[@id^='"+tablink.slice(0,3)+"']").hide();
        $(this).parents('.ms-tabs').find("#"+tablink).show();
        return false;
    })
}


/***HB: WE DON'T HAVE A FLICKBOX - DON'T NEED THIS???
// video-flickbox function
videoFlickBox=function(el,auto){

		$(el+" h2").append("<div><a href=# class=flickf></a> <a href='#' class=flicker4> <a href='#' class=flicker3> </a><a href='#' class=flicker2> </a><a href='#' class=flicker1> </a><a href=# class=flickb></a></div>");

		$(el+" h2 a.flicker1").addClass('high')
		$(el+" h2 a.flickf").click(function(){
				var a=this;
				$(a).hide();
				$(el+" h2").prepend('<span class=flickf></span>');

				clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3);

				var u = parseInt($(el+" div.ms-flick-list").find('ul').css('margin-left').replace('px',''));

				if(u!=-864){$(el+" div.ms-flick-list").find('ul').animate({marginLeft:u-288},800,function(){$(el+' span.flickf').remove();$(a).show()})}
				$(el+" h2 a[@class^='flicker']").removeClass('high');

				if(u==0){$('a.flicker2').addClass('high')}
				if(u==-288){$('a.flicker3').addClass('high')}
				if(u==-576){$('a.flicker4').addClass('high')}
				if(u==-864){$('a.flicker4').addClass('high');$(el+' span.flickf').remove();$(a).show()}

		return false;

		})

		$(el+" h2 a.flickb").click(function(){
				var a=this;
				$(a).hide();
				$(el+" h2").append('<span class=flickb></span>');

				clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3)
				var u = parseInt($(el+" div.ms-flick-list").find('ul').css('margin-left').replace('px',''));
				if(u!=0){$(el+" div.ms-flick-list").find('ul').animate({marginLeft:u+288},800,function(){$(el+' span.flickb').remove();$(a).show()})}
				$(el+" h2 a[@class^='flicker']").removeClass('high');

				if(u==0){$('a.flicker1').addClass('high');$(el+' span.flickb').remove();$(a).show()}
				if(u==-288){$('a.flicker1').addClass('high')}
				if(u==-576){$('a.flicker2').addClass('high')}
				if(u==-864){$('a.flicker3').addClass('high')}
		return false;
		})

		$(el+" h2 a[@class^='flicker']").click(function(){
			$(el+" h2 a[@class^='flicker']").removeClass('high');
			if($(this).attr('class')=='flicker1'){clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3);clearTimeout(msflbt4);clearTimeout(msflbt5);$(el+" div.ms-flick-list").find('ul').animate({marginLeft:0},800)};

			if($(this).attr('class')=='flicker2'){clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3);clearTimeout(msflbt4);clearTimeout(msflbt5);$(el+" div.ms-flick-list").find('ul').animate({marginLeft:-288},800)};

			if($(this).attr('class')=='flicker3'){clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3);clearTimeout(msflbt4);clearTimeout(msflbt5);$(el+" div.ms-flick-list").find('ul').animate({marginLeft:-576},800)};

			if($(this).attr('class')=='flicker4'){clearTimeout(msflbt1);clearTimeout(msflbt2);clearTimeout(msflbt3);clearTimeout(msflbt4);clearTimeout(msflbt5);$(el+" div.ms-flick-list").find('ul').animate({marginLeft:-864},800)};

			$(this).addClass('high');
		return false;
		})
	}

	videoFlickBoxAuto=function(){
		window.msflbt1 = setTimeout("$('#ms-flickbox-1 div.ms-flick-list').find('ul').animate({marginLeft:-288},800);$('#ms-flickbox-1 h2 a[@class^=flicker]').removeClass('high');$('#ms-flickbox-1 .flicker2').addClass('high')",10000);
		window.msflbt2 = setTimeout("$('#ms-flickbox-1 div.ms-flick-list').find('ul').animate({marginLeft:-576},800);$('#ms-flickbox-1 h2 a[@class^=flicker]').removeClass('high');$('#ms-flickbox-1 .flicker3').addClass('high');",21000);
		window.msflbt3 = setTimeout("$('#ms-flickbox-1 div.ms-flick-list').find('ul').animate({marginLeft:-864},800);$('#ms-flickbox-1 h2 a[@class^=flicker]').removeClass('high');$('#ms-flickbox-1 .flicker4').addClass('high');",32000);

		var x = $('#ms-flickbox-1 .ms-flick-list ul li:lt(2)').clone();
		$('#ms-flickbox-1 .ms-flick-list ul').append(x);


		window.msflbt4 = setTimeout("$('#ms-flickbox-1 div.ms-flick-list').find('ul').animate({marginLeft:-1152},800)",43000)
		window.msflbt5 = setTimeout("$('#ms-flickbox-1 div.ms-flick-list').find('ul').css('margin-left',0);$('#ms-flickbox-1 h2 a[@class^=flicker]').removeClass('high');$('#ms-flickbox-1 .flicker1').addClass('high');$('#ms-flickbox-1 .ms-flick-list ul').find('li:gt(7)').remove();videoFlickBoxAuto();",44000);


	}

	configVideo= function(vidXML) {
		var newHTML = "";
			$.ajax({
			    url: vidXML,
			    dataType: 'xml',
			    timeout: 1000,
			    success: function(xml){


					$(xml).find("video").each(function(i) {
						if(i<8){
							newHTML += "<li><a href='" + $(this).attr("src") + "'><img src='" + $(this).attr("bigThumb") + "'><p>" + $(this).attr("title") + "</p></a></li>";
						}
					});
					$("#ms-flickbox-1 .ms-flick-list ul").html(newHTML);
					videoFlickBox('#ms-flickbox-1','yes');
					videoFlickBoxAuto();
			    }
		});
	}


***************/


/** photo-galleries function **/
configGallery=function(el, galXML) {
    var newHTML = "";
    $.ajax({
        url: galXML,
        dataType: 'xml',
        timeout: 2000,
        success: function(xml){

            $(xml).find("ARTICLE").each(function(i) {

                if (i < 4) {
                    newHTML += "<li><a href='" + $(this).attr("link") + "'><img src='" + $(this).attr("galPicThumb") + "' width='68' height='60'><h4>" + $(this).find("HLHEAD").text() + "</h4><p>" + $(this).find("LLSNIPPET").text() + "</p></a></li>";
                }

                if(i==0){
                    var bigim = $(this).attr("galPicThumb");
                    bigim = bigim.replace('68x60','247');
                    $('#bigThumb').html("<img src='"+bigim+"' />");

                    galh4 = $(this).find("HLHEAD").text();
                    galp = $(this).find("LLSNIPPET").text();
                }

            });

            $("#ms-photo-box1 .ms-photo-gallery").html(newHTML);

            $(el).find('li:first a').addClass('highlight');
            $(el).find('span').html("<h4>"+galh4+"</h4><p>"+galp+"</p>");

            $(el+ ' ul.ms-photo-gallery li a').mouseover(function(){
                $(el+ ' ul.ms-photo-gallery li a').removeClass('highlight');
                $(this).addClass('highlight');
                var im = $(this).find('img').attr('src');
                im = im.replace('68x60','247');
            $('#bigThumb img').attr('src',im);

                var h4 = $(this).find('h4').html();
                var p = $(this).find('p').html();
                $(el).find('span').html("<h4>"+h4+"</h4><p>"+p+"</p>");

            })
        }
    })

}




/* article bookmark ul */
htmlStuff = function(){
$('.ms-art-bookmark').prepend("<a class='' href='#'>Save to</a>");
		$(".ms-art-bookmark").hover(
			function(){
				$(this).find("ul").show().css('z-index','4');
				$(this).find('a').addClass('ms-bookmarks')},

			function(){
				$(this).find("ul").hide();
				$(this).find('a').removeClass('ms-bookmarks')
			});
};



/* thickbox function */
articleImages=function(p){

    var w = $(p).eq(0).width();
    var h = $(p).eq(0).height();

    var m = "/"+w+"x"+h+"/";
    $(p).each(function(){
        if($(this).attr('src').match(m)){
            var s=$(this).attr('src').split(w+'x'+h);
            $(this).wrap("<a href='"+s[0]+"800x600"+s[1]+"' class='thickbox' title=''></a>")
        }

    });

}


//HB: we don't have a profileGallery do we?
///* profile gallery function */
//profileGallery = function(p){
//
//	var lis = Math.ceil(($(p+ ' .ms-profiles-r1 li').length)/2);
//
//	var widthoflis = Math.ceil(lis/4);
//	lis = lis*69;
//	$(p+ ' .ms-profiles-r1').css('width',lis);
//
//	$(p).find('.ms-profiles-prev a,.ms-profiles-next a').click(function(){
//
//		//l is the amount we want to go back or forth
//		var l = parseInt($(this).attr('rel'));
//
//		// current margin left position
//		var c = parseInt($(p+ ' .ms-profiles-r1').css('margin-left'));
//
//		//maxmargin is max to go right
//		var maxmargin = (((widthoflis-1)*277)*-1);
//
//
//		var pos = c+l;
//
//		if(pos>0){pos=0}
//		if(maxmargin==c && l!="277"){pos=maxmargin};
//
//
//		$(p+ ' .ms-profiles-r1').animate({marginLeft:pos})
//		return false;
//
//	})
//
//
//}


//call functions
//NavInit();
articleImages('.ms-art-subcol img');
articleImages('#article-gallery img');
//profileGallery('.ms-box-profiles');
htmlStuff();
