function openPopUp(url, windowName, w, h, scrollbar) {
			
	   var dW=$(document).width();	
       var winl = (dW - w) / 2;
       winprops = 'height='+h+',width='+w+',top=250,left='+winl+',scrollbars='+scrollbar ;
	   win = window.open(url, windowName, winprops);
       if (parseInt(navigator.appVersion) >= 4) { 
          	win.window.focus(); 
       } 
	   
}
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

$(document).ready(function() {
	$("#contactForm").validate();	
	send_a_friend_init();	
	//$("#generalContent .title").dropShadow({left: 3, top: 3, blur: 1, color: "#000", opacity: 0.20, swap: false});
	
	$("#jCarouselLite").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 1
    });
	/*
	  auto: 800,
   	  speed: 4000
	*/
	
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'100px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'130px'},{queue:false,duration:160});
	});


	init_video_links();
		  
	$('.video_holder').each(function() {
/*		var html = "<div class='play_overlay' style='display:none'><img src='"+site_url+"/images/playOverlay.png'/></div>";
		$(this).append(html);
		$(this).parents('.video_place_holder').css('width', $(this).attr('current_type') == 'high' ? 550 : 480);*/
	});


	$('.video_place_holder .video_holder').bind('mouseenter', function() {
		var top = $(this).offset().top;
		var left = $(this).offset().left;
		var width = $(this).width();
		var height = $(this).height();

		var o_width = $(this).find('.play_overlay').width();
		var o_height = $(this).find('.play_overlay').width();

		var o_left = (width/2) - (o_width/2);
		var o_top = (height/2) - (o_height/2);
		$(this).find('.play_overlay').css('top', top + o_top);
		$(this).find('.play_overlay').css('left', left + o_left + 15);
		$(this).find('.play_overlay').fadeIn();
	});
	$('.video_place_holder .video_holder').bind('mouseleave', function() {
		$(this).find('.play_overlay').fadeOut();
	});

	$('.play_overlay').click(function() {
		alert('Play functionality here');
	});
	
});
 


function showbox(pop_options){
	// Calculate the top and left position of the lightbox
		var body_width = $('body').width() - 80;
		var body_height = $(document).height();
		var left = (body_width / 2) -  (820 /2);
		var top = (window.pageYOffset || document.documentElement.scrollTop || 0) + 100;
	// ------------------------------------------
	
	/*var class_schedules_text = '';
	class_schedules.each(function(){
		class_schedules_text =  class_schedules_text + $(this).text() + '<br/>';
	});
	class_schedules_text = '<div style="width: 280px; margin-bottom: 10px; float: left; margin-left: 5px;">'+class_schedules_text+'</div>';
	*/
	if (!pop_options) pop_options =	{};
	if (!pop_options.name) pop_options.name = 'Leona Lewis Performance on "So you think you can Dance" UK edition';
	if (!pop_options.src) pop_options.src = site_url + '/images/pop_image.jpg';
	if (!pop_options.desc) pop_options.desc = 'Jermaine Choreographed Leona New Single "You Got You" Where he incorporate Ballet, Jazz and Contemporary, to tell the story of When a person is scared to love, or have problems trusting, because of a hurtful past or present. What happens when they find someone, and they say it\'s ok, I Got You.';
	if (!pop_options.button_text) pop_options.button_text = 'VIEW VIDEO';

	html = "<img class='pop_image' src='index.php?page=get_file&name="+pop_options.pop_image+"'/><div class='name'>"+pop_options.name+"</div><div class='desc'>"+pop_options.desc+"</div>";
	buttons_html = '';
	if (pop_options.video != '') {
		buttons_html +=  "<input type='button' class='red_button pop_button_video' value='View Video'/>&nbsp;&nbsp;";
	}
	if (pop_options.article != '') {
		buttons_html += "<input type='button' class='red_button pop_button_article' value='View Article'/>&nbsp;&nbsp;";
	}
	if (pop_options.link != '') {
		buttons_html += "<input type='button' class='red_button pop_button_link' value='View Link' link='"+pop_options.link +"'/>&nbsp;&nbsp;";
	}

	if (buttons_html != '') {
		html += '<div class="button_holder">' + buttons_html + "</div>";
	}


	var box_content = '';
	overlay = "<div id='overlay'></div>	<div id='light_box'><img src='"+site_url+"/images/close1.jpg' id='close_box' /><div id='box_content'>"+html+"</div></div>";
	
	$('div#light_box,div#overlay').remove();
	$('body').prepend(overlay);
	$('body').prepend(box_content);
	$('div#overlay').height(body_height);
	$('div#light_box').css('left', left);
	$('div#light_box').css('top', top);
	$('div#light_box div#box_content .pop_button_video').unbind('click');
	$('div#light_box div#box_content .pop_button_video').bind('click', function() { pop_options.action('video', pop_options.id, pop_options.section, $(this));});

	$('div#light_box div#box_content .pop_button_article').unbind('click');
	$('div#light_box div#box_content .pop_button_article').bind('click', function() { pop_options.action('article', pop_options.id, pop_options.section, $(this));});

	$('div#light_box div#box_content .pop_button_link').unbind('click');
	$('div#light_box div#box_content .pop_button_link').bind('click', function() { pop_options.action('link', pop_options.id, pop_options.section, $(this));});

	$('div#light_box div#box_content .pop_image').css('padding-bottom', function() { return 240-parseInt($(this).height());});
	$('div#light_box').slideDown('slow');
	$("div#light_box img#close_box").click(function(){
		$('div#light_box,div#overlay').remove();
	});
}

function showbox_custom(html, width, height, close_function){
	// Calculate the top and left position of the lightbox
		var body_width = $('body').width() - 80;
		var body_height = $(document).height();
		var left = (body_width / 2) -  (width /2);
		var top = (window.pageYOffset || document.documentElement.scrollTop || 0) + 100;
	// ------------------------------------------
	
	/*var class_schedules_text = '';
	class_schedules.each(function(){
		class_schedules_text =  class_schedules_text + $(this).text() + '<br/>';
	});
	class_schedules_text = '<div style="width: 280px; margin-bottom: 10px; float: left; margin-left: 5px;">'+class_schedules_text+'</div>';
	*/
	
	var box_content = '';
	overlay = "<div id='overlay'></div>	<div id='light_box'><img src='"+site_url+"/images/close1.jpg' id='close_box' /><div id='box_content'>"+html+"</div></div>";
	
	$('div#light_box,div#overlay').remove();
	$('body').prepend(overlay);
	$('body').prepend(box_content);
	$('div#overlay').height(body_height);
	$('div#light_box').css('left', left);
	$('div#light_box').css('top', top);
	$('div#light_box').height(height);
	$('div#light_box').width(width);
	$('div#light_box').slideDown('slow');
	$("div#light_box img#close_box").click(function(){
		if (typeof eval(close_function) == 'function') {
			eval(close_function+'()');
		}
		$('div#light_box,div#overlay').remove();
	});
}

function show_videos() {
	if ($('.video_holder').attr('current_type') == 'high') {
		$('div.video_high').show();
	}
	else if ($('.video_holder').attr('current_type') == 'low') {
		$('div.video_low').show();
	}
}
function init_scroll_click(init_scroll) {
	$('.video_box').unbind('click');
	$('.video_box').click(function() {
		var src = $(this).find('.video_image img').attr('src');
		var name = $(this).find('.video_name').html();
		var id = $(this).attr('id');
		var type = $(this).attr('type');
		var popup_options = {};
//		popup_options.name = name;
		popup_options.src = src;
		popup_options.action = popup_action;

		$(this).find('div.row_data').each(function() {
			var name = $(this).attr('name');
			var value = $(this).html();
			popup_options[name] = value;
		});
		popup_options.name = popup_options.title;
		showbox(popup_options);
	});
	if (init_scroll === true) {
		$("#scroller").jCarouselLite({
			btnNext: ".next_button",
			btnPrev: ".prev_button",
			afterEnd: function() { init_scroll_click(false);},
			visible: 1
		});
	}
}

function popup_action(type, id, section, object) {
	var href = '';
	switch (type) {
		case 'video':
			href = site_url + "?page=project&id="+id+'&section='+section;
		break;
		case 'article':
			href = site_url + "?page=paper&id="+id+'&section='+section;
		break;
		case 'link':
			href = $(object).attr('link');
			window.open(href);
			return false;
		break;
	}

	if (href != '') location.href = href;
}

function init_video_links() {
	$('.video_links').unbind('click');
	$('.video_links').bind('click', function() {
		var type = $(this).attr('type');
		var for_video = $(this).attr('link_for_video');
		var video_object = $('#'+for_video);
		if ($(video_object).attr('current_type') != type) {
			switch (type) {
				case 'high':
					$(video_object).removeClass('video_holder_low');
					$(video_object).addClass('video_holder_high');

				break;
				case 'low':
					$(video_object).removeClass('video_holder_high');
					$(video_object).addClass('video_holder_low');
				break;
			}
			$(video_object).attr('current_type', type);
			var h_type = (type == 'high') ? 'low' : 'high';
			$(video_object).find('.video_'+h_type).hide();
			$(video_object).find('.video_'+type).show();
			$(video_object).parents('.video_place_holder').animate({width: (type == 'high') ? 480 : 400});
		}
	});
}

function send_a_friend_init() {
	$('.home_page_send_button').unbind('click');
	$('.home_page_send_button').bind('click', function() {
		send_a_friend_show('show_videos');
	});

}
function send_a_friend_show(callback) {
		$('div.video_high, div.video_low').hide();
		showbox_custom($('div#form_dialog_send_friend_form').html(), 395, 212, callback);
		$('.send_friend_submit_action').unbind('click');
		$('.send_friend_submit_action').bind('click', function() {
			var rel_id = $('.home_page_send_button').attr('rel_id');
			var section = $('.home_page_send_button').attr('section');
			var add_params = $('#send_a_friend_real_form').serialize();
			var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			var err = '';

			if ($.trim($('#send_to').val()) == '') {
				err += "Please enter the Email of the Recipient\n";
			}

			if ($.trim($('#send_from').val()) == '') {
				err += "Please enter the Your name\n";
			}

			if ($.trim($('#send_to').val()) != '' && !filter.test($('#send_to').val())) {
				err += "Please enter the a Valid Recipient email address\n";
			}

			if ($.trim($('#sent_comment').val()) == '') {
				err += "Please enter a Comment\n";
			}

			if (err != '') {
				alert(err);
				return false;
			}
			$('#box_content').html('<div id="loader" style="width:200px;height:200px;font-size:13px;font-style:italic"><img src="'+site_url+'/images/ajax_loader.gif" align="middle" style="padding-right:15px"/>Sending...</div>');
			$.get(site_url +"/?page=project_info&action=send_email&id="+rel_id+'&section='+section+'&'+add_params, function(response) {
				$('#box_content').html($('div#form_dialog_send_friend_submit').html());
			}, 'text');
		});
}
