// JavaScript Document


$(document).ready(init);
//variable for Video Thumbnails
var numClick=0;
var numVideos = 0;
var numPages = 0;
var currentPage = 1;
//variables for News Thumbnails
var numClickNews=0;
var numNews = 0;
var numPagesNews = 0;
var currentPageNews = 0;
var currentPageN = 0;

//function get Thumbnail videos
function getScreen( url, size ) {
if(url === null){
return ""; } size = (size === null) ? "big" : size; var vid; var results;

 results = url.match("[\\?&]v=([^&#]*)");

 vid = ( results === null ) ? url : results[1];

 if(size == "small"){
 return "http://img.youtube.com/vi/"+vid+"/2.jpg"; }
 else {
 return "http://img.youtube.com/vi/"+vid+"/0.jpg"; }
 }

function init()
{
	//NEWS THUMBNAILS
	numNews = thumbNumNews / 100;
	numPagesNews = Math.ceil(numNews / 4);
	
	$('.thumbNews').click(
		function()
		{
			numClickNews = $(this).attr('id');
	
			if (currentPageNews != numClickNews)
			{
				var difference = numClickNews - currentPageNews;
				//alert(currentPageNews);
				if(currentPageNews < numClickNews)
				{
					var difference = numClickNews - currentPageNews;
					//alert(difference);
					switch(difference)
					{
						case 1:
							$('#fullNews').animate({top:'-=500'},500);
							currentPageNews = numClickNews;
						break;
						case 2:
							$('#fullNews').animate({top:'-=1000'},600);
							currentPageNews = numClickNews;
						break;
						case 3:
							$('#fullNews').animate({top:'-=1500'},700);
							currentPageNews = numClickNews;
						break;
						case 4:
							$('#fullNews').animate({top:'-=2000'},800);
							currentPageNews = numClickNews;
						break;
						case 5:
							$('#fullNews').animate({top:'-=2500'},900);
							currentPageNews = numClickNews;
						break;
						case 6:
							$('#fullNews').animate({top:'-=3000'},1000);
							currentPageNews = numClickNews;
						break;
						case 7:
							$('#fullNews').animate({top:'-=3500'},1100);
							currentPageNews = numClickNews;
						break;
					}
				}else if(currentPageNews > numClickNews)
				{
					switch(difference)
					{
						case -1:
							$('#fullNews').animate({top:'+=500'},500);
							currentPageNews = numClickNews;
						break;
						case -2:
							$('#fullNews').animate({top:'+=1000'},600);
							currentPageNews = numClickNews;
						break;
						case -3:
							$('#fullNews').animate({top:'+=1500'},700);
							currentPageNews = numClickNews;
						break;
						case -4:
							$('#fullNews').animate({top:'+=2000'},800);
							currentPageNews = numClickNews;
						break;
						case -5:
							$('#fullNews').animate({top:'+=2500'},900);
							currentPageNews = numClickNews;
						break;
						case -6:
							$('#fullNews').animate({top:'+=3000'},1000);
							currentPageNews = numClickNews;
						break;
						case -7:
							$('#fullNews').animate({top:'+=3500'},1100);
							currentPageNews = numClickNews;
						break;
					}
				}
			}
			 
		}
	);
	
	$('#next2').click(nextPageNews);
	$('#previous2').click(previousPageNews);
	newsThumbWidth();
	
	//VIDEO THUMBNAILS 
	numVideos = thumbNum / 100;
	numPages = Math.ceil(numVideos / 4);
	$('.thumbs').click(
		function()
		{
			 if ($.browser.msie) 
			 { 
				$("#videoLarge2").attr('src', "http://www.youtube.com/embed/" + $(this).attr('id'));
			 }else{ 
				$("#videoLarge2").attr('src', "http://www.youtube.com/v/" + $(this).attr('id'));
			 }
		}
	);
	
	$('#next').click(nextPage);
	$('#previous').click(previousPage);
	
	thumbWidth();
	
	
}

//---------------VIDEOS
function videoDisplayed()
{
	
	document.getElementById("videoLarge1").value = document.getElementById("videoLarge2").src = "http://www.youtube.com/v/" ;
}
function nextPage()
{
	if( currentPage !== numPages )
	{
		$('#videoList').animate({
					left: '-=400'
					}, 1000);
		currentPage++;
	}
}
function previousPage()
{
	if(currentPage !== 1)
	{
		$('#videoList').animate({
				left: '+=400'
				}, 1000);
		currentPage--;
	}
}

function thumbWidth()
{
	$('ul #videoList').css('width', thumbNum);
}
//-----------NEWS
function nextPageNews()
{
	if( currentPageN !== numPagesNews && currentPageN<1 )
	{
		$('#newsList').animate({
					left: '-=375'
					}, 1000);
		currentPageN++;
	}
}
function previousPageNews()
{
	if(currentPageN !== 0)
	{
		$('#newsList').animate({
				left: '+=375'
				}, 1000);
		currentPageN--;
	}
}
function newsThumbWidth()
{
	$('ul #newsList').css('width', thumbNumNews);
}
