
function change_location(url, field, value)
{
	window.location = "?" + url + "&" + field + "=" + value;
}

function confirmation(msg, url)
{
	if(confirm(msg)) location.href = url;
}


$(document).ready(function() {

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

	/* forms */
	$("select.view_by_url").change( function() {
		change_location($(this).attr("use_url"), 'view_by', this.value);
	});

	/* member login */
	$("#member input").focus( function() {
		this.value = '';
	});
	$("#member input").blur( function() {
		if(this.value=='')this.value='Username'; 
		return false;
	});

	/* search box */
	$("#search input").focus( function() {
		this.value = '';
	});
	$("#search input").blur( function() {
		if(this.value=='')this.value='SEARCH'; 
		return false;
	});

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

	// Send Form
	$("a.SendForm").click(function(){
		document.myform.submit();
		return false;
	});

	// Window Close
	$("a.CloseWin").click(function(){
		window.close();
		return false;
	});

	// External Link
	$("a.externalLink").click(function(){
		window.open(this.href,'newwin');
		return false;
	});

	// Video Player Link
	$("a.VideoPlayer").click(function(){
		window.open(this.href,"Video_Player","width=550,height=520,outerwidth=555,outerheight=607,top=50,left=50,");
		return false;

	});

	// Learn More Information
	$("a.LearnMore").click(function(){
		window.open(this.href,"Learn_More","width=710,height=595,outerwidth=715,outerheight=620,top=50,left=50,");
		return false;

	});

	// Order AICE Bid Form
	$("a.BidForm").click(function(){
		window.open(this.href,"Order_AICE_Bid_Form","width=710,height=559,outerwidth=715,outerheight=592,top=50,left=50,");
		return false;

	});

	// Newsletter Signup
	$("a.Newsletter").click(function(){
		window.open(this.href,"Newsletter_Signup","width=402,height=371,outerwidth=410,outerheight=413,top=50,left=50,");
		return false;

	});

	// Trailer History
	$("a.TrailerHistory").click(function(){
		window.open(this.href,"Trailer_History","width=410,height=655,outerwidth=415,outerheight=698,top=50,left=50,");
		return false;

	});

	// Search Name Go
	$("a.SearchNameGo").click(function(){
		document.view_by_search.submit();
		return false;

	});

	// Search Terms
	$("a.SearchTerm").click(function(){
		document.site_search.submit();
		return false;
	});


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

	/* menu js */
	$("#nav-one li").hover(
		function(){
			if ( ($(this).children().is("img")) || ($(this).children("a").children().is("img")) )
			{
				$(this).find("img").attr("src", './images/nav/' + $(this).attr("id").substring(4) + '_on.gif');
				$(this).children("ul").show();
			}
		},
		function(){
			if ( ( ($(this).children().is("img")) || ($(this).children("a").children().is("img")) )  )
			{				
				$(this).find("img").attr("src", './images/nav/' + $(this).attr("id").substring(4) + '_off.gif');
				$(this).children("ul").hide();
			}
		}
	);

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

	$("li#sub_resource_center").hover(
        function(){ 
			$("div.selectPhoto").css("visibility","hidden"); 
			$("div.selectPast").css("visibility","hidden"); 
			$("div.selectFinalist").css("visibility","hidden"); 
		}, 
        function(){ 
			$("div.selectPhoto").css("visibility","visible"); 
			$("div.selectPast").css("visibility","visible"); 
			$("div.selectFinalist").css("visibility","visible"); 
		} 
    );		

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

	/* mouseover images */
	$("a.over img").mouseover(function(){
		this.src = './images/common/' + this.id + '_on.png';
		return false;
	});

	$("a.over img").mouseout(function(){
		this.src = './images/common/' + this.id + '.png';
		return false;
	});


	$("#event").mouseover(function(){
		$("#photo01 a").addClass("on");
		$("#event a").addClass("on");
		$("#event a .descr").removeClass("descr");
		$("#event a .descr").addClass("descr_on");
		return false;
	});

	$("#event").mouseout(function(){
		$("#photo01 a").removeClass("on")
		$("#event a").removeClass("on");
		$("#event a .descr").removeClass("descr_on");
		$("#event a .descr").addClass("descr");
		return false;
	});


	$("#event2").mouseover(function(){
		$("#photo02 a").addClass("on");
		$("#event2 a").addClass("on");
		$("#event2 a .descr").removeClass("descr");
		$("#event2 a .descr").addClass("descr_on");
		return false;
	});

	$("#event2").mouseout(function(){
		$("#photo02 a").removeClass("on")
		$("#event2 a").removeClass("on");
		$("#event2 a .descr").removeClass("descr_on");
		$("#event2 a .descr").addClass("descr");
		return false;
	});

	$("#event3").mouseover(function(){
		$("#photo03 a").addClass("on");
		$("#event3 a").addClass("on");
		$("#event3 a .descr").removeClass("descr");
		$("#event3 a .descr").addClass("descr_on");
		return false;
	});

	$("#event3").mouseout(function(){
		$("#photo03 a").removeClass("on")
		$("#event3 a").removeClass("on");
		$("#event3 a .descr").removeClass("descr_on");
		$("#event3 a .descr").addClass("descr");
		return false;
	});

	


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

	// init parameters
	var current_photo = 0;

	$.place_photo = function(offset){ // place current_photo

		current_photo = current_photo + offset;
		if (current_photo >= photos.length) current_photo = 0;
		if (current_photo < 0) current_photo = photos.length-1;

		// put proper numbers in place
		$("#photo_gallery_photo_num").empty();
		$("#photo_gallery_photo_num").append(current_photo+1);
		$("#photo_gallery_photo_total").empty();
		$("#photo_gallery_photo_total").append(photos.length);

		// put caption in place
		$("#photo_gallery_caption").empty();
		$("#photo_gallery_caption").append(photos[current_photo].caption);

		// put image in place
		$("#photo_gallery_image").attr({src : photos[current_photo].image, alt : photos[current_photo].title});
		$("#photo_gallery_image").load( function() { $("#photo_gallery_image").show(); $("#photo_gallery_caption").show(); } );

	};

	if (window.photos) {
		if (window.photos.length > 0) {
			$.place_photo(0); // place inherited current_photo
		}
	}

	// place actions on arrows
	$("#photo_gallery_next").click(function(){

		$("#photo_gallery_caption").hide();
		$("#photo_gallery_image").hide();
		$.place_photo(1);
	});

	$("#photo_gallery_prev").click(function(){

		$("#photo_gallery_caption").hide();
		$("#photo_gallery_image").hide();
		$.place_photo(-1);
	});



});





