var headline1 = null;
var headline2 = null;
var headline3 = null;
var headline4 = null;
var headline5 = null;
var headlineShowing = 0;

var feature1 = null;
var feature2 = null;
var feature3 = null;
var feature4 = null;
var feature5 = null;
var featureShowing = 0;

var weekly1 = null;
var weekly2 = null;
var weekly3 = null;
var weekly4 = null;
var weekly5 = null;
var weeklyShowing = 0;

function setHeadlineShowing(h){
	headlineShowing = h;
}

function setFeatureShowing(f){
	featureShowing = f;
}

function setWeeklyShowing(w){
	weeklyShowing = w;
}

$(document).ready(function(){

	headline1 = document.getElementById('smallPhoto1');
	headline2 = document.getElementById('smallPhoto2');
	headline3 = document.getElementById('smallPhoto3');
	headline4 = document.getElementById('smallPhoto4');
	headline5 = document.getElementById('smallPhoto5');
	var headlineCount = 0;

	if(headline1 != null){
		headlineCount ++;
		$(headline1).mouseover(function () {
			showHeadline(1);
		});
	}
	if(headline2 != null){
		headlineCount ++;
		$(headline2).mouseover(function () {
			showHeadline(2);
		});
	}
	if(headline3 != null){
		headlineCount ++;
		$(headline3).mouseover(function () {
			showHeadline(3);
		});
	}
	if(headline4 != null){
		headlineCount ++;
		$(headline4).mouseover(function () {
			showHeadline(4);
		});
	}
	if(headline5 != null){
		headlineCount ++;
		$(headline5).mouseover(function () {
			showHeadline(5);
		});
	}

	if(headlineCount > 1){

		if(headline1 != null){
			$(document.getElementById('right_1')).mousedown(function () {
				if(headline2 != null)
					showHeadline(2);
				else if(headline3 != null)
					showHeadline(3);
				else if(headline4 != null)
					showHeadline(4);
				else if(headline5 != null)
					showHeadline(5);
			});
			$(document.getElementById('left_1')).mousedown(function () {
				if(headline5 != null)
					showHeadline(5);
				else if(headline4 != null)
					showHeadline(4);
				else if(headline3 != null)
					showHeadline(3);
				else if(headline2 != null)
					showHeadline(2);
			});
		}

		if(headline2 != null){
			$(document.getElementById('right_2')).mousedown(function () {
				if(headline3 != null)
					showHeadline(3);
				else if(headline4 != null)
					showHeadline(4);
				else if(headline5 != null)
					showHeadline(5);
				else if(headline1 != null)
					showHeadline(1);
			});
			$(document.getElementById('left_2')).mousedown(function () {
				if(headline1 != null)
					showHeadline(1);
				else if(headline5 != null)
					showHeadline(5);
				else if(headline4 != null)
					showHeadline(4);
				else if(headline3 != null)
					showHeadline(3);
			});
		}

		if(headline3 != null){
			$(document.getElementById('right_3')).mousedown(function () {
				if(headline4 != null)
					showHeadline(4);
				else if(headline5 != null)
					showHeadline(5);
				else if(headline1 != null)
					showHeadline(1);
				else if(headline2 != null)
					showHeadline(2);
			});
			$(document.getElementById('left_3')).mousedown(function () {
				if(headline2 != null)
					showHeadline(2);
				else if(headline1 != null)
					showHeadline(1);
				else if(headline5 != null)
					showHeadline(5);
				else if(headline4 != null)
					showHeadline(4);
			});
		}

		if(headline4 != null){
			$(document.getElementById('right_4')).mousedown(function () {
				if(headline5 != null)
					showHeadline(5);
				else if(headline1 != null)
					showHeadline(1);
				else if(headline2 != null)
					showHeadline(2);
				else if(headline3 != null)
					showHeadline(3);
			});
			$(document.getElementById('left_4')).mousedown(function () {
				if(headline3 != null)
					showHeadline(3);
				else if(headline2 != null)
					showHeadline(2);
				else if(headline1 != null)
					showHeadline(1);
				else if(headline5 != null)
					showHeadline(5);
			});
		}

		if(headline5 != null){
			$(document.getElementById('right_5')).mousedown(function () {
				if(headline1 != null)
					showHeadline(1);
				else if(headline2 != null)
					showHeadline(2);
				else if(headline3 != null)
					showHeadline(3);
				else if(headline4 != null)
					showHeadline(4);
			});
			$(document.getElementById('left_5')).mousedown(function () {
				if(headline4 != null)
					showHeadline(4);
				else if(headline3 != null)
					showHeadline(3);
				else if(headline2 != null)
					showHeadline(2);
				else if(headline1 != null)
					showHeadline(1);
			});
		}
	}

	//feature stories
	feature1 = document.getElementById('feature_small1');
	feature2 = document.getElementById('feature_small2');
	feature3 = document.getElementById('feature_small3');
	feature4 = document.getElementById('feature_small4');
	feature5 = document.getElementById('feature_small5');

	if(feature1 != null){
		featureShowing = 1;
		$(feature1).mouseover(function () {
			showFeature(1);
		});
	}
	if(feature2 != null){
		$(feature2).mouseover(function () {
			showFeature(2);
		});
	}
	if(feature3 != null){
		$(feature3).mouseover(function () {
			showFeature(3);
		});
	}
	if(feature4 != null){
		$(feature4).mouseover(function () {
			showFeature(4);
		});
	}
	if(feature5 != null){
		$(feature5).mouseover(function () {
			showFeature(5);
		});
	}


	//weekly features
	weekly1 = document.getElementById('weekly_small1');
	weekly2 = document.getElementById('weekly_small2');
	weekly3 = document.getElementById('weekly_small3');
	weekly4 = document.getElementById('weekly_small4');
	weekly5 = document.getElementById('weekly_small5');

	if(weekly1 != null){
		weeklyShowing = 1;
		$(weekly1).mouseover(function () {
			showWeekly(1);
		});
	}
	if(weekly2 != null){
		$(weekly2).mouseover(function () {
			showWeekly(2);
		});
	}
	if(weekly3 != null){
		$(weekly3).mouseover(function () {
			showWeekly(3);
		});
	}
	if(weekly4 != null){
		$(weekly4).mouseover(function () {
			showWeekly(4);
		});
	 }
	if(weekly5 != null){
		$(weekly5).mouseover(function () {
			showWeekly(5);
		});
	}
  });

  function showHeadline(headlineNum){

	 if(headlineShowing != headlineNum){
		  $("div#headline" + headlineShowing).hide();
		  $("div#headlineText" + headlineShowing).hide();
		  document.getElementById("smallPhoto" + headlineShowing).className = "smallHeadlinePhoto";
	  }
	  $("div#headline" + headlineNum).show();
	  $("div#headlineText" + headlineNum).show();

	  document.getElementById("smallPhoto" + headlineNum).className = "smallHeadlinePhotoFullOpacity";
	  headlineShowing = headlineNum;
  }

  function showFeature(featureNum){
	  if(featureShowing != featureNum){
		  $("div#featureStory" + featureShowing).hide();
		  document.getElementById("feature_small" + featureShowing).className = "subHeadlinePhoto";
	  }
	  $("div#featureStory" + featureNum).show();
	  document.getElementById("feature_small" + featureNum).className = "subHeadlinePhotoFullOpacity";
	  featureShowing = featureNum;
  }

  function showWeekly(weeklyNum){

	  if(weeklyShowing != weeklyNum){
		  $("div#weeklyFeature" + weeklyShowing).hide();
		  document.getElementById("weekly_small" + weeklyShowing).className = "subHeadlinePhoto";
	  }

	  $("div#weeklyFeature" + weeklyNum).show();
	  document.getElementById("weekly_small" + weeklyNum).className = "subHeadlinePhotoFullOpacity";
	  weeklyShowing = weeklyNum;
  }