var base_url = 'http://www.grignard.com/';
function clearForm(formIdent) 
{ 
  	var form, elements, i, elm; 
  	form = document.getElementById ? document.getElementById(formIdent) : document.forms[formIdent]; 
	if (document.getElementsByTagName)
	{
		elements = form.getElementsByTagName('input');
		for( i=0, elm; elm=elements.item(i++); )
		{
			if (elm.getAttribute('type') == "text")
			{
				elm.value = '';
			}
		}
	}

	// Actually looking through more elements here
	// but the result is the same.
	else
	{
		elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.type == "text")
			{
				elm.value ='';
			}
		}
	}
}

function Msg(message){
	document.getElementById('err_message').innerHTML=message;
  	document.getElementById("err_message_container").style.display = "block";
	var pattern=/SUCCESS!!/i;
	if(pattern.test(message)){
		scroll(0,0);
	}	
}

function transBody(){
	document.getElementById('main_body').style.filter='alpha(opacity=30)'; 
	document.getElementById('main_body').style.mozOpacity='0.3'; 
	document.getElementById('main_body').style.opacity='0.3';
	document.getElementById('main_body').style.khtmlOpacity='.3'; 

}

function editWindow(url, width, height){
var str="";
 str += "height=" + height;
  str += ",innerHeight=" + height;
  str += ",width=" + width;
  str += ",innerWidth=" + width;
 str += ",menubar=1";
  str += ",resizable=1";
  str += ",scrollbars=1";

 window.open (url,"editwindow",str);
}


function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

$('#facebox').livequery(function() {
	//seat form...more forms can be added after this
	$(this).find('#facebox_seat_form').livequery(function() {
      	$(this).ajaxForm({
			target: '#saved_div',
			beforeSubmit: setAdminSeatColor,
        	success: function(html) {
      			$.facebox.close();
        	}
		});
    });
	//another form starts after here
});

$(document).ready(function() {

	//portfolio image click function
	$('.portfolio_thumb_link').live('click', function() {
		var id = $(this).attr("id").replace('portfolio_thumb_link_', '');
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content.php?id=" + id,
  			context: $('#rightContainer'),
  			success: function(data){
    			$(this).html(data);
				$('.portfolio_right_col_entry_selected').each(function(){
				   $(this).attr("class", "portfolio_right_col_entry");
				});
				$('.portfolio_thumb_selected').each(function(){
				   $(this).attr("class", "portfolio_thumb");
				});
				$('#portfolio_right_col_entry_' + id).attr("class", "portfolio_right_col_entry_selected");
				$('#portfolio_thumb_' + id).attr("class", "portfolio_thumb_selected");
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_description.php?id=" + id,
  			context: $('#leftContainer'),
  			success: function(data){
    			$(this).html(data);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_blurb.php?id=" + id,
  			context: $('#top_blurb_area'),
  			success: function(data){
    			$(this).html(data);
  			}
		});
	});

	//portfolio right col entry div click function
	$('.portfolio_right_col_entry_link').live('click', function() {
		var id = $(this).attr("id").replace('portfolio_right_col_entry_link_', '');;
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content.php?id=" + id,
  			context: $('#rightContainer'),
  			success: function(data){
    			$(this).html(data);
				$('.portfolio_right_col_entry_selected').each(function(){
				   $(this).attr("class", "portfolio_right_col_entry");
				});
				$('.portfolio_thumb_selected').each(function(){
				   $(this).attr("class", "portfolio_thumb");
				});
				$('#portfolio_right_col_entry_' + id).attr("class", "portfolio_right_col_entry_selected");
				$('#portfolio_thumb_' + id).attr("class", "portfolio_thumb_selected");
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_description.php?id=" + id,
  			context: $('#leftContainer'),
  			success: function(data){
    			$(this).html(data);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_blurb.php?id=" + id,
  			context: $('#top_blurb_area'),
  			success: function(data){
    			$(this).html(data);
  			}
		});
	});

	//staff image click function
	$('.staff_thumb_link').live('click', function() {
		var id = $(this).attr("id").replace('staff_thumb_link_', '');;
		$.ajax({
  			url: base_url + "handlers/get_staff_content.php?id=" + id,
  			context: $('#thePeople_rightContainer'),
  			success: function(data){
    			$(this).html(data);
				$('.staff_right_col_entry_selected').each(function(){
				   $(this).attr("class", "staff_right_col_entry");
				});
				$('.staff_thumb_selected').each(function(){
				   $(this).attr("class", "staff_thumb");
				});
				$('#staff_right_col_entry_' + id).attr("class", "staff_right_col_entry_selected");
				$('#staff_thumb_' + id).attr("class", "staff_thumb_selected");
  			}
		});
	});

	//staff right col entry div click function
	$('.staff_right_col_entry_link').live('click', function() {
		var id = $(this).attr("id").replace('staff_right_col_entry_link_', '');;
		$.ajax({
  			url: base_url + "handlers/get_staff_content.php?id=" + id,
  			context: $('#thePeople_rightContainer'),
  			success: function(data){
    			$(this).html(data);
				$('.staff_right_col_entry_selected').each(function(){
				   $(this).attr("class", "staff_right_col_entry");
				});
				$('.staff_thumb_selected').each(function(){
				   $(this).attr("class", "staff_thumb");
				});
				$('#staff_right_col_entry_' + id).attr("class", "staff_right_col_entry_selected");
				$('#staff_thumb_' + id).attr("class", "staff_thumb_selected");
  			}
		});
	});

	//next portfolio click function
	$('#portfolio_next_link').live('click', function() {
		var page = $(this).attr("href").replace('portfolio.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_right_nav_content.php?type=portfolio&ptype=portfolio.php&p=" + page,
  			context: $('#FBScreen'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content.php?p=" + page,
  			context: $('#rightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});

		$.ajax({
  			url: base_url + "handlers/get_thumbs_content.php?type=portfolio&ptype=portfolio.php&p=" + page,
  			context: $('#leftContainerInner'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_blurb.php?p=" + page,
  			context: $('#top_blurb_area'),
  			success: function(data){
				var c_arr2 = data.split("::data_id_split::");
    			$(this).html(c_arr2[0]);
  			}
		});
		return false;
	});

	//back portfolio click function
	$('#portfolio_back_link').live('click', function() {
		var page = $(this).attr("href").replace('portfolio.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_right_nav_content.php?type=portfolio&ptype=portfolio.php&p=" + page,
  			context: $('#FBScreen'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content.php?p=" + page,
  			context: $('#rightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_thumbs_content.php?type=portfolio&ptype=portfolio.php&p=" + page,
  			context: $('#leftContainerInner'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_portfolio_content_blurb.php?p=" + page,
  			context: $('#top_blurb_area'),
  			success: function(data){
				var c_arr2 = data.split("::data_id_split::");
    			$(this).html(c_arr2[0]);
  			}
		});
		return false;
	});

	//next staff click function
	$('#staff_next_link').live('click', function(){
		var page = $(this).attr("href").replace('the_people.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_right_nav_content.php?type=staff&p=" + page,
  			context: $('#FBScreen'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_staff_content.php?p=" + page,
  			context: $('#thePeople_rightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_thumbs_content.php?type=staff&ptype=the_people.php&p=" + page,
  			context: $('#leftContainerInner'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		return false;
	});

	//back staff click function
	$('#staff_back_link').live('click', function(){
		var page = $(this).attr("href").replace('the_people.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_right_nav_content.php?type=staff&p=" + page,
  			context: $('#FBScreen'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_staff_content.php?p=" + page,
  			context: $('#thePeople_rightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_thumbs_content.php?type=staff&ptype=the_people.php&p=" + page,
  			context: $('#leftContainerInner'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		return false;
	});

	//about cat entry link click function
	$('.about_cat_link').live('click', function() {
		var id = $(this).attr("id").replace('about_cat_link_', '');;
		$.ajax({
  			url: base_url + "handlers/get_about_cat_content.php?id=" + id,
  			context: $('#aboutRightContainer'),
  			success: function(data){
    			$(this).html(data);
				$('.about_cat_div_selected').each(function(){
				   $(this).attr("class", "about_cat_div");
				});
				$('#about_cat_div_' + id).attr("class", "about_cat_div_selected");
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_about_cat_images.php?id=" + id,
  			context: $('#aboutMiddleContainer'),
  			success: function(data){
    			$(this).html(data);
  			}
		});
	});

	//next about click function
	$('#about_cats_next_link').live('click', function(){
		var page = $(this).attr("href").replace('about.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_about_left_nav_content.php?p=" + page,
  			context: $('#aboutLeftContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_about_cat_content.php?p=" + page,
  			context: $('#aboutRightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_about_cat_images.php?p=" + page,
  			context: $('#aboutMiddleContainer'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		return false;
	});

	//back about click function
	$('#about_cats_back_link').live('click', function(){
		var page = $(this).attr("href").replace('about.php?p=', '');
		$.ajax({
  			url: base_url + "handlers/get_about_left_nav_content.php?p=" + page,
  			context: $('#aboutLeftContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_about_cat_content.php?p=" + page,
  			context: $('#aboutRightContainer'),
  			success: function(data){
				var c_arr = data.split("::data_id_split::");
    			$(this).html(c_arr[0]);
  			}
		});
		$.ajax({
  			url: base_url + "handlers/get_about_cat_images.php?p=" + page,
  			context: $('#aboutMiddleContainer'),
  			success: function(data){
				var c_arr1 = data.split("::data_id_split::");
    			$(this).hide().html(c_arr1[0]).fadeIn(2500);
  			}
		});
		return false;
	});

	//$('#slide1 .slide');
	//setInterval(function(){
	//	$('#cont_cont .slide').filter(':visible').fadeOut(3000,function(){
	//		if($(this).next('div.slide').size()){
	//			var id = $(this).next().attr("id").replace('slider_div_', '');
	//			$('#slide1').css("background-image", "url(" + $(this).next().attr("rel") + ")");
	//			$(this).next().fadeIn(3000);
//
//			}
//			else{
//				$('#slide1').css("background-image", "url(" + $('#cont_cont .slide').eq(0).attr("rel") + ")");
//				$('#cont_cont .slide').eq(0).fadeIn(3000);
//			}
//		});
//	},3000);

	$('#slide1').cycle({
			fx:     'scrollLeft', 
		    speed:   300,  
			pause:    1,
		    timeout:	5000, 
		    next:   '#sliderright', 
		    prev:   '#sliderleft',
		});

	//add more here
});

