x13_search_submit	= function()
{
	var search_query	= document.getElementById('x13_header_search_field_input').value;

	search_query		= search_query.replace(/[^a-zA-Z 0-9\.\,]+/g, '');
	search_query		= search_query.replace(/\s/g, '+');

	window.location		= 'http://www.zumber.com/search/' + search_query + '/';

	return false;
}
x13_updateClock		= function()
{
	var currentTime		= new Date ();
	var monthArray		= new Array(
					'January','February','March',
					'April','May','June','July',
					'August','September','October',
					'November','December'
				  );

	var currentHours	= currentTime.getHours();
	var currentMinutes	= currentTime.getMinutes();
	var currentSeconds	= currentTime.getSeconds();
	var currentDay		= currentTime.getDate();
	var currentMonth	= currentTime.getMonth();
	var currentYear		= currentTime.getFullYear();

	currentMinutes		= (currentMinutes < 10 ? "0" : "") + currentMinutes;
	currentSeconds		= (currentSeconds < 10 ? "0" : "") + currentSeconds;
	var timeOfDay		= (currentHours < 12) ? "AM" : "PM";
	currentHours		= (currentHours > 12) ? currentHours - 12 : currentHours;
	currentHours		= (currentHours == 0) ? 12 : currentHours;
	var currentTimeString	= monthArray[currentMonth] + " " + x13_ordi(currentDay) + " " + currentYear + " - " + currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
	var clock_element	= document.getElementById("x13_header_menu_clock");

	clock_element.innerHTML	= '<div class="x13_shadow_clock" title="' +
					currentTimeString +
				'"><span id="x13_header_menu_clock_span">' +
					currentTimeString +
				'</span></div>';

	clock_element.style.paddingLeft = (240 - document.getElementById('x13_header_menu_clock_span').offsetWidth) + 'px';
}
x13_ordi		= function(n)
{
	map		= {1:'st',21:'st',31:'st',2:'nd',22:'nd',3:'rd',23:'rd'};
	return n+(map[n]||"th");
}
x13_sfHover		= function()
{
	if (!document.getElementsByTagName) return false;
	var sfEls = document.getElementById("x13_header_menu").getElementsByTagName("li");

	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function()
		{
			this.className+=" x13_sfhover";
		}
		sfEls[i].onmouseout=function()
		{
			this.className=this.className.replace(new RegExp(" x13_sfhover\\b"), "");
		}
	}
}
x13_find_link		= function(ele)
{
	var menu_link	= ele.getElementsByTagName('a');

	for (var i = 0; i < menu_link.length; i++)
	{
		if (menu_link[i].getAttribute('href'))
		{
			window.location = menu_link[i].getAttribute('href');
		}
	}
}
x13_boxview_toggle	= function(id, state)
{
	switch (state)
	{
		case 'expand':
			document.getElementById('x13_box_'+id+'_content').style.display				= 'block';
			document.getElementById('x13_box_'+id+'_footer').style.display				= 'block';
			document.getElementById('x13_box_'+id+'_header_toolbox_collapse').style.display		= 'inline';
			document.getElementById('x13_box_'+id+'_header_toolbox_expand').style.display		= 'none';
			document.getElementById('x13_box_'+id+'_header_corner_left_bottom').style.visibility	= 'hidden';
			document.getElementById('x13_box_'+id+'_header_corner_right_bottom').style.visibility	= 'hidden';
		break;
		case 'collapse':
			document.getElementById('x13_box_'+id+'_content').style.display				= 'none';
			document.getElementById('x13_box_'+id+'_footer').style.display				= 'none';
			document.getElementById('x13_box_'+id+'_header_toolbox_collapse').style.display		= 'none';
			document.getElementById('x13_box_'+id+'_header_toolbox_expand').style.display		= 'inline';
			document.getElementById('x13_box_'+id+'_header_corner_left_bottom').style.visibility	= 'visible';
			document.getElementById('x13_box_'+id+'_header_corner_right_bottom').style.visibility	= 'visible';
		break;
	}
	return false;
}
x13_go			= function(url)
{
	if (!x13_switch)
	{
		document.location = url;
	}
}
x13_text_length		= function( source, target, limit )
{
	var ele_source	= document.getElementById( source );
	var ele_target	= document.getElementById( target );
	var ele_length	= ( limit - ele_source.value.length );

	ele_target.innerHTML = ele_length;

	if ( ele_length <= 0 )
	{
		return false;
	}

	return true;
}

x13_comment_submit	= function()
{
	var ele_id	= document.getElementById( 'x13_comment_form_id' );
	var ele_name	= document.getElementById( 'x13_comment_form_name' );
	var ele_email	= document.getElementById( 'x13_comment_form_email' );
	var ele_comment	= document.getElementById( 'x13_comment_form_comment' );
	var ele_main	= document.getElementById( 'x13_comment_form_main' );
	var ele_send	= document.getElementById( 'x13_comment_form_send' );
	

	var ret_check	= true;

	if ( !x13_comment_check( ele_name.value, 'a' ) ) { ret_check = false; };
	if ( !x13_comment_check( ele_email.value, 'e' ) ) { ret_check = false; };
	if ( !x13_comment_check( ele_comment.value, 'c' ) ) { ret_check = false; };

	if ( ret_check == true )
	{
		ele_main.style.display = 'none';
		ele_send.style.display = 'block';

		var req_data	= 'id=' + ele_id.value + '&' +
				  'name=' + ele_name.value + '&' +
				  'email=' + ele_email.value + '&' +
				  'comment=' + ele_comment.value;

		x13_comment_ajax( '/ajax/comment/send/', req_data );
	}
}
x13_comment_check	= function( value, type )
{
	switch (type)
	{
		case 'a':
			var regex_aln = /^([a-zA-Z0-9\ ]+)$/;

			if ( !regex_aln.test( value ) ) 
			{
				x13_comment_error( 'Error with Name', 'name' );
				return false;
			}
		break;
		case 'e':
			var regex_eml = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;

			if ( !regex_eml.test( value ) )
			{
				x13_comment_error( 'Error with Email', 'email' );
				return false;
			}
		break;
		case 'c':
			if ( !( value.length < 1500 ) )
			{
				x13_comment_error( 'Error with Comment', 'comment' );
				return false;
			}
		break;
	}

	return true;
}
x13_comment_error	= function( string, ele )
{
	alert( string );

	return false;
}
x13_comment_response	= function( data )
{
	var ret_val	= '';
	response	= data.split( ':', 2 );

	switch ( response[0] )
	{
		case 'received':
			switch ( response[1] )
			{
				case 'OK':
					ret_val = 'Your comment has been submitted and is pending editorial review.<br />&nbsp;';
				break;
				case 'WAIT':
					ret_val = 'Please wait a little longer before trying to submit another comment.<br />&nbsp;';
				break;
			}
		break;
		case 'error':
			ret_val = 'There has been an error submitting the comment.<br /><br />' +
				  '<a href="#comment" onclick="x13_comment_reset();">Click here to try again</a><br />&nbsp;';
		break;
	}
	document.getElementById('x13_comment_form_send').innerHTML = ret_val;
}
x13_comment_reset	= function()
{
	var ele_main	= document.getElementById( 'x13_comment_form_main' );
	var ele_send	= document.getElementById( 'x13_comment_form_send' );

	ele_main.style.display = 'block';
	ele_send.style.display = 'none';
}
x13_comment_ajax	= function( url, data )
{
	var ajax_h;

	try { ajax_h = new ActiveXObject('Msxml2.XMLHTTP'); }
	catch (e)
	{
		try { ajax_h = new ActiveXObject('Microsoft.XMLHTTP'); }
		catch (e2)
		{
			try { ajax_h = new XMLHttpRequest(); }
			catch (e3) { ajax_h = false; }
		}
	}

	ajax_h.onreadystatechange = function()
	{
		if (ajax_h.readyState == 4)
		{
			if (ajax_h.status == 200)
			{
				x13_comment_response( "received:" + ajax_h.responseText );
			}
			else
			{
				x13_comment_response( "error:" + ajax_h.status );
			}
		}
	};

	ajax_h.open("POST", url, true);
	ajax_h.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax_h.send(data);
}

var x13_rating_max;
var x13_rating_holder;
var x13_rating_preset;
var x13_rating_rated;

x13_rating_rater	= function( count )
{
	x13_rating_max = 0;

	if ( !count || !count.parentNode ) { return false; }

	for ( counter = 0; counter < count.parentNode.childNodes.length; counter++ )
	{
		if ( count.parentNode.childNodes[ counter ].nodeName == "A" )
		{
			x13_rating_max++;
		}
	}

	if ( !x13_rating_rated )
	{
		x13_rating_star	= count.id.replace( "x13_rating_star_", "" );
		x13_rating_a	= 0;

		for ( counter = 1; counter <= x13_rating_max; counter++ )
		{
			if ( counter <= x13_rating_star )
			{
				document.getElementById( "x13_rating_star_" + counter ).className = 'x13_rating_star_on';
//				document.getElementById( "x13_rating_status" ).innerHTML = count.title;
				x13_rating_holder = x13_rating_a + 1;
				x13_rating_a++;
			}
			else
			{
				document.getElementById( "x13_rating_star_" + counter).className = '';
			}
		}
	}
}
x13_rating_off		= function( ele )
{
	if ( !x13_rating_rated )
	{
		if ( !x13_rating_preset )
		{
			for ( counter = 1; counter <= x13_rating_max; counter++ )
			{
				document.getElementById( "x13_rating_star_" + counter).className = '';
//				document.getElementById( "x13_rating_status" ).innerHTML = ele.parentNode.title;
			}
		}
		else
		{
			x13_rating_rater( x13_rating_preset );
//			document.getElementById( "x13_rating_status" ).innerHTML = document.getElementById( "x13_rating_saved" ).innerHTML;
		}
		x13_rating_rater( document.getElementById( 'x13_rating_star_' + x13_rating_preset ) );
	}
}
x13_rating_rate		= function( ele )
{
	if ( !x13_rating_rated )
	{
		x13_rating_preset = ele;
		x13_rating_rated = 1;
		x13_rating_send( ele );
		x13_rating_rater( ele )
	}
}
x13_rating_set		= function( rate )
{
	x13_rating_rater( document.getElementById( 'x13_rating_star_' + x13_rating_preset ) );
}
x13_rating_send		= function( ele )
{
	var ele_id	= document.getElementById( 'x13_rating_id' );
	var ele_value	= ele;

	var ret_check	= true;

	if ( !x13_rating_check( ele_id.value, 'd' ) ) { ret_check = false; };
	if ( !x13_rating_check( ele_value.title, 'd' ) ) { ret_check = false; };

	if ( ret_check == true )
	{
		var req_data	= 'id=' + ele_id.value + '&' +
				  'rating=' + ele_value.title;

		x13_rating_ajax( '/ajax/ratings/send/', req_data );
	}
}
x13_rating_check	= function( value, type )
{
	switch (type)
	{
		case 'd':
			var regex_num = /^([0-9]+)$/;

			if ( !regex_num.test( value ) ) 
			{
				return false;
			}
		break;
	}

	return true;
}
x13_rating_ajax		= function( url, data )
{
	var ajax_h;

	try { ajax_h = new ActiveXObject('Msxml2.XMLHTTP'); }
	catch (e)
	{
		try { ajax_h = new ActiveXObject('Microsoft.XMLHTTP'); }
		catch (e2)
		{
			try { ajax_h = new XMLHttpRequest(); }
			catch (e3) { ajax_h = false; }
		}
	}

	ajax_h.onreadystatechange = function()
	{
		if (ajax_h.readyState == 4)
		{
			if (ajax_h.status == 200)
			{
				x13_rating_response( "received:" + ajax_h.responseText );
			}
			else
			{
				x13_rating_response( "error:" + ajax_h.status );
			}
		}
	};

	ajax_h.open("POST", url, true);
	ajax_h.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax_h.send(data);
}
x13_rating_response	= function( data )
{
	var ret_val	= '';
	response	= data.split( ':', 2 );

	switch ( response[0] )
	{
		case 'received':
			switch ( response[1] )
			{
				case 'OK':
					ret_val = 'Rating Submitted. &nbsp;&nbsp;';
				break;
				case 'LIMIT':
					ret_val = 'Only one vote per person. &nbsp;&nbsp;';
				break;
			}
		break;
		case 'error':
			ret_val = 'ERROR';
		break;
	}
	document.getElementById( "x13_rating_status" ).innerHTML = ret_val;
}

var x13_image_expand_timer;

x13_image_expand	= function( obj, img, comment )
{
	var expander			= document.getElementById( 'x13_article_image_expand' );
	var originator			= document.getElementById( 'article_image_main' );

	expander.style.top		= x13_ele_pos_y( obj ) + 'px';
	expander.style.left		= x13_ele_pos_x( obj ) + 'px';

	expander.innerHTML		= '<div id="x13_article_image_expand_inlay">' +
						'<img src="http://common.zumber.com/images/spacer.gif" ' +
						'style="background-image:url(\'' +
							img +
						'\');" id="x13_article_image_expand_inlay_main" />' +
					  '</div>' +
					  comment +
					  '<img src="' +
						img +
					  '" id="x13_article_image_expand_dummy">';

	expander.setAttribute('exwidth', '310');
	expander.setAttribute('exheight', '310');

	expander.style.visibility	= 'visible';

	var originator_dummy		= document.getElementById( 'x13_article_image_expand_dummy' );
	var originator_step_x		= (originator_dummy.width - 300) / 10;
	var originator_step_y		= (originator_dummy.height - 300) / 10;

	setTimeout(
		"x13_image_expand_go(" +
			originator_step_x +
			", " +
			originator_step_y +
		")",
		1
	);

}
x13_image_expand_go	= function( ex, ey )
{
	var expander			= document.getElementById( 'x13_article_image_expand' );
	var originator			= document.getElementById( 'x13_article_image_expand_inlay_main' );
	var originator_dummy		= document.getElementById( 'x13_article_image_expand_dummy' );

	expand_width			= eval( expander.getAttribute( 'exwidth' ) );
	expand_height			= eval( expander.getAttribute( 'exheight' ) );

	expand_width			+= ex;
	expand_height			+= ey;

	expander.style.width		= expand_width;
	expander.style.height		= expand_height;
	originator.style.width		= expand_width - 10;
	originator.style.height		= expand_height - 10;

	expander.setAttribute('exwidth', expand_width);
	expander.setAttribute('exheight', expand_height);

	if ( expander.getAttribute('exwidth') >= originator_dummy.width )
	{
		expander.style.height		= expand_height + 12;
		clearTimeout( x13_image_expand_timer );
	}
	else
	{
		x13_image_expand_timer		= setTimeout(
							"x13_image_expand_go(" +
								ex +
								", " +
								ey +
							")",
							1
						  );
	}
}

x13_ele_pos_x		= function( obj )
{
	var cur_left	= 0;

	if ( obj.offsetParent )
	{
		while( 1 )
		{
			cur_left += obj.offsetLeft;

			if ( !obj.offsetParent )
			{
				break;
			}

			obj = obj.offsetParent;
		}
	}
	else if ( obj.x )
	{
		cur_left	+= obj.x;
	}

	return cur_left;
}
x13_ele_pos_y		= function( obj )
{
	var cur_top	= 0;

	if ( obj.offsetParent )
	{
		while( 1 )
		{
			cur_top += obj.offsetTop;

			if ( !obj.offsetParent )
			{
				break;
			}

			obj = obj.offsetParent;
		}
	}
	else if ( obj.y )
	{
		cur_top		+= obj.y;
	}

	return cur_top;
}

x13_onload		= function()
{
	if ( document.getElementById( 'x13_box_news_world_video_content_holder' ) )
	{
		var news_video = document.getElementById( 'x13_box_news_world_video_content_holder' );
		var news_loadr = document.getElementById( 'x13_box_news_world_video_content_loader' );

		news_video.style.display = 'block';
		news_loadr.style.display = 'none';
	}
}

var x13_slide_show_slide = new Array;
var x13_slide_show_buffer = new Array;
var x13_slide_show_timer = new Array;

x13_browser_isie	= function()
{
	return /msie/i.test( navigator.userAgent ) && !/opera/i.test( navigator.userAgent );
}

x13_slideshow		= function( id )
{
	x13_slide_show_slide[ id ] = 0;

	if ( !document.images )
	{
		return;
	}

	var ele_slide_nav	= document.getElementById( 'x13_slide_show_cast_' + id );

	for (i = 0; i < x13_slide_show[ id ].length - ( ( x13_browser_isie() ) ? 1 : 0 ); i++)
	{
		x13_slide_show_buffer[ i ]	= new Image;
		x13_slide_show_buffer.src	= x13_slide_show[ id ][ i ][ 0 ];

		ele_slide_nav.innerHTML		+= '<a href="' +
							x13_slide_show[ id ][ i ][ 0 ] +
						   '">' +
							'<img src="' +
								x13_slide_show[ id ][ i ][ 0 ].replace(".jpg", "-80x80.jpg")  +
							'" id="x13_slide_show_cast_' +
								id +
							'_' +
								i +
							'" class="x13_slide_show_cast_stand"' +
							' onclick="x13_slideshow_select( ' +
								id +
							', ' +
								i +
							' ); return false;" />' +
						   '</a>';
	}

	x13_slideshow_cycle( id, 1 );
}
x13_slideshow_cycle	= function( id, repeat )
{
	if ( !document.images )
	{
		return;
	}
	if ( x13_browser_isie() && ( x13_slide_show_slide[ id ] == x13_slide_show[ id ].length - 1 ) )
	{
		x13_slide_show_slide[ id ] = 0;
	}

	var ele_performer	= document.getElementById( 'x13_slide_show_performer_' + id );
	var ele_script		= document.getElementById( 'x13_slide_show_script_' + id );


	ele_performer.style.backgroundImage	= "url('" + x13_slide_show[ id ][ x13_slide_show_slide[ id ] ][ 0 ] + "')";
	ele_script.innerHTML			= x13_slide_show[ id ][ x13_slide_show_slide[ id ] ][ 1 ];

	for ( i = 0; i < x13_slide_show[ id ].length - ( ( x13_browser_isie() ) ? 1 : 0 ); i++ )
	{
		if ( i == x13_slide_show_slide[ id ] )
		{
			document.getElementById( 'x13_slide_show_cast_' + id + '_' + i ).className = 'x13_slide_show_cast_hover';
		}
		else
		{
			document.getElementById( 'x13_slide_show_cast_' + id + '_' + i ).className = 'x13_slide_show_cast_stand';
		}
	}

	if ( x13_slide_show_slide[ id ] < (x13_slide_show[ id ].length - 1) )
	{
		x13_slide_show_slide[ id ]++;
	}
	else
	{
		x13_slide_show_slide[ id ] = 0;
	}

	if ( repeat == 1 )
	{
		x13_slide_show_timer[ id ] = setTimeout( "x13_slideshow_cycle( " + id + ", 1 )", 2500 );
	}
}
x13_slideshow_select	= function( id, cast )
{
	clearTimeout(x13_slide_show_timer[ id ]);

	x13_slide_show_slide[ id ] = cast;
	x13_slideshow_cycle( id, 0 );
}

if (window.attachEvent)
{
	window.attachEvent("onload", x13_sfHover);
}

var x13_switch = false;