// JavaScript Document

$(document).ready(function(){
						   
	// Hack for IE6 LHS nav
	if ($.browser.msie && $.browser.version == 6.0) { 
		$('.secnav li').css({'display': 'inline'}); 
		$('.secnav li li').css({'display': 'inline-block'}); 
}
	
	//add default search text if it is empty
	if( $("#keywords").attr("value") == "" ){
		$("#keywords").attr("value", "Search");
	}
		
	//remove default search text
	$("#keywords").focus(function(){
		if( $(this).attr("value") == "Search" ){
			$(this).attr("value", "");
		}
	});

	//reset default search text
	$("#keywords").blur(function(){
		if( $(this).attr("value") == "" ){
			$(this).attr("value", "Search");
		}
	});
	
	//check search text before submitting
	$("#search-btn").click(function(){
		if( $("#keywords").attr("value") == "Search" ){
			$("#keywords").attr("value", "");
		}
	});	
	
	// form imput buttons
	$("input.btn").hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
	});
	
	// regions form - hide controls
	$('.region .controls').hide();
	
	// regions form submit
	$('#regions').change(function() {
		if($(this).attr('value') != ''){
			$(this).closest("form").submit();
		}
	});
	
	// custom button styles
	$('input.style1').hover(function(){
			$(this).addClass('style1-hover');
		}, function(){
			$(this).removeClass('style1-hover');
	});

	$('input.style2').hover(function(){
			$(this).addClass('style2-hover');
		}, function(){
			$(this).removeClass('style2-hover');
	});

    $('#mycarousel').jcarousel();

	// video gallery transcript collapser
	
									 
	Collapser.init();

	$('.collapsible').addClass('collapsible-icon');
	
	$('.collapsible .button').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});


    var $pageTools = '<h3>Text sizing:</h3>';
	$pageTools += '<ul class="sizing">';
	$pageTools += '<li><a href="#" id="header_text_small" title="Decrease text size. "><span>A</span><sup>-</sup></a></li>';
	$pageTools += '<li class="reset"><a href="#" id="header_text_medium" class="current" title="Reset text size. "><span>A</span></a></li>';
	$pageTools += '<li><a href="#" id="header_text_large" title="Increase text size. "><span>A</span><sup>+</sup></a></li>';
	$pageTools += '</ul>';
	$pageTools += '<h3>Email this page:</h3>';
	$pageTools += '<ul>';
	$pageTools += '<li><div class="share"><a class="dialog" href="#share-box"><span>Email</span></a></div></li>';
	$pageTools += '</ul>';
	$pageTools += '<h3>Print this page:</h3>';
	$pageTools += '<ul><li><a href="javascript:window.print();" class="print" title="Print this page. "><span>Print</span></a></li></ul>';
	//write the tools in the DOM
	if($('.tools').hasClass('nothome')){
		$('.pagetools .fb').before($pageTools);
	}

	/*var $shareForm = '<div id="share-box" class="dialog-box" title="Share with a friend">';
	$shareForm += '<div id="ajax-content"></div>';
	$shareForm += '<form id="shareform" class="standard" method="post" action="/Send-Video-link">';
	$shareForm += '<fieldset>';
	$shareForm += '<h3 class="hidden">Share with a friend</h3>';
	$shareForm += '<div class="block">';
	$shareForm += '<label for="ShareText">Email:</label>';
	$shareForm += '<input type="text" name="send_to" class="box" id="send_to" />';
	$shareForm += '</div>';
	$shareForm += '<div id="shareform-button" class="controls">';
	$shareForm += '<span class="default-btn"><span class="lhs"></span><input type="submit" alt="Send Email" value="Send Email" class="btn" /><span class="rhs"></span></span>';
	$shareForm += '<input type="hidden" id="node_id" name="node_id" value="{$module_result.node_id}" />';
	$shareForm += '</div>';
	$shareForm += '</fieldset>';
	$shareForm += '</form>';
	$shareForm += '</div>';
	
	//write the form in the DOM
	$('.page-wrap').after($shareForm);*/

	$(function() {
		$('.dialog-box').dialog({
			autoOpen: false,
			modal: true,
			height: 130,
			width: 330
		});
			
		$('.dialog').click(function() {
			if($(this).attr('href') != "undefine")
				$($(this).attr('href')).dialog('open');
			return false;
		});
	});

	$("#shareform").submit(function(){
		var send_email_url = "/layout/set/ajax/Send-Email/(email)";
		send_email_url = send_email_url + '/' +$("#send_to").val() + '/(node_id)/' +$("#node_id").val();
		var sharebutton = $("#shareform-button").html();
		$("#shareform-button").html('<img style="background: transparent none repeat scroll 0% 0%; margin-left: 30px;" src={/literal}{"loadingAjaxAnimation.gif"|ezimage}{literal} />');
		
		$.post(send_email_url,{
					subject: $("#subject").val(),
					action: "Send"
				}, function(data) {					
			$("#ajax-content").html(data);
			$("#shareform-button").html(sharebutton);
		});
		return false;
	});
		
		
	// remove glossary terms from factboxes
	$(".factbox .tooltip-link").each(function(){
		var content = $(this).html();
		$(this).after(content);
		$(this).remove();
	});
	$(".factbox-green .tooltip-link").each(function(){
		var content = $(this).html();
		$(this).after(content);
		$(this).remove();
	});
	$(".factbox-red .tooltip-link").each(function(){
		var content = $(this).html();
		$(this).after(content);
		$(this).remove();
	});
});




