// JavaScript Document
var left_content = get_cookie('left_content');
var myDate = new Date();

function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure) {
	var cookie_string = name + "=" + escape ( value );
	
	if (exp_y) {
	var expires = new Date (exp_y, exp_m, exp_d);
	cookie_string += "; expires=" + expires.toGMTString();
	}
	
	if (path)
		cookie_string += "; path=" + escape ( path );
	
	if (domain)
		cookie_string += "; domain=" + escape ( domain );
	
	if (secure)
		cookie_string += "; secure";
	
	document.cookie = cookie_string;
}

function get_cookie (cookie_name)
{
  var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

  if (results)
    return (unescape(results[2]));
  else
    return null;
}

function delete_cookie (cookie_name)
{
	var cookie_date = new Date ();  // current date & time
	cookie_date.setTime (cookie_date.getTime() - 1);
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

$(document).ready(function() {
	
	//accordion effect for history
	
	$('.history > div').hide();
	$('.history > h3').click(function() {
		var img_attr = $(this).children('img').attr('src');
		var $nextDiv = $(this).next();
		var $visibleSiblings = $nextDiv.siblings('div:visible');
		if ($visibleSiblings.length ) {
			$visibleSiblings.slideUp('normal', function() {
			$nextDiv.slideToggle('normal');
			});
		} 
		else {
			$nextDiv.slideToggle('normal');
		}
		$('.history > h3').children('img').attr('src', 'images/expand.gif');
		$('.history > h3').children('img').attr('alt', '+');
		if (img_attr == 'images/collapse.gif') {
			$(this).children('img').attr('src', 'images/expand.gif');
			$(this).children('img').attr('alt', '+');
		}
		else {
			$(this).children('img').attr('src', 'images/collapse.gif');
			$(this).children('img').attr('alt', '-');
		}
	}).css({cursor: 'pointer'});
	
	//end - accordion effect for history
  
    //video player
	
	$(".video_thumbnail").click(function() {
		var video_code = $(this).next().val();
		$("#play_video_here").fadeIn();		
		$("#play_video_here").html('');
		$("#play_video_here").html(video_code);
	}).css({cursor: 'pointer'});
	
	$(".video_thumbnail_link").click(function() {
		var video_code = $(this).parent().prev().children().next().val();
		$("#play_video_here").fadeIn();		
		$("#play_video_here").html('');
		$("#play_video_here").html(video_code);
	});
	//end - video player
	
	//forum collapsible
	if ((left_content != null) && (left_content == 'hide')) {
		$('#left_content').hide();
		$('#middle_content').css({width: '920px'});
		$('#demolishor').text('collapse [-]');
	}
	else {
		$('#demolishor').text('expand [+]');
	}
	
	$('#demolishor').click(function () {
		//alert(myDate.getFullYear() + 1);
		//alert(myDate.getDate());
		//alert(myDate.getMonth());
		left_content = get_cookie('left_content');
		if ((left_content != null) && (left_content == 'hide')) {
			$('#left_content').show();
			$('#middle_content').css({width: '700px'});
			$(this).text('expand [+]');
			if (left_content != null) {
				delete_cookie("left_content");
			}
		}
		else {
			$('#left_content').hide();
			$('#middle_content').css({width: '920px'});
			$(this).text('collapse [-]');
			if (left_content == null) {
				set_cookie('left_content', 'hide', myDate.getFullYear() + 1, myDate.getMonth(),  myDate.getDate());
			}
		}	
	});
	//end - forum collapsible
});