function showTime()
{
	var now 	= new Date();
	var hours 	= now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var timeval = '';
	var ampm 	= '';
	var day		= now.getDay();
	var month	= now.getMonth();
	var today 	= now.getDate();
	var year 	= now.getYear() + 1900;
	
	var dayarr 	= new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	var montharr= new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	if(hours > 12)
	{
		timeval = hours - 12;
		ampm 	= ' PM';
	}
	else
	{
		timeval += hours;
		ampm	= ' AM';
	}
	
	if(minutes < 10)
	{
		timeval += ":0" + minutes;
	}
	else
	{
		timeval += ":" + minutes;
	}
	
	if(seconds < 10)
	{
		timeval += ":0" + seconds;
	}
	else
	{
		timeval += ":" + seconds;
	}
	timeval += ampm;
	
	timeval = dayarr[day] + ', ' + montharr[month] + ', ' + today + ' ' + year + ', ' + timeval;
	
	document.getElementById('date').innerHTML = timeval;
	setTimeout("showTime()", 1000);
}

// jquery site 
jQuery(document).ready(function(){
//$(document).ready(function(){
/*
| for form field input control
*/
	//showTime();

/*/ 	jQuery('.noSpaces').alphanumeric();
	jQuery('.numericOnly').numeric();
	jQuery('.emailOnly').alphanumeric({allow:'@_-'});
	jQuery('.grpEmail').alphanumeric({allow:'@;_-.'});*/

/*
| for article mailto friends popup.
*/
	// Open the email popup when click in the mailto icon.s
	jQuery('.article_email').click(function(){
		jQuery('#mailto_container').show('fast');
		alert();
	});
	// article mailto friends close
	jQuery('.closeBtn').click(function(){
		jQuery('#mailto_container').hide('fast');
	});
// end of article mailto functions.

/*
| for bar of the poll options.
*/
	// get graph
	getOptionGraph();
	// when view button is clicked.
	jQuery('.poll_results').click(function(){
		var id = jQuery(this).attr('name');
		var state = jQuery(this).attr('state');
		if(state == 0){
			jQuery(this).attr({'state':'1'});
			jQuery(this).val('जनमत');
			jQuery('#poll_result_list'+id).show('slow');
			jQuery('#poll_options_list'+id).hide('fast');
			jQuery('#poll_submit_'+id).hide('fast');
		} else {
			jQuery(this).attr({'state':'0'});
			jQuery(this).val('नतिजा हेर्नुहोस।');
			jQuery('#poll_result_list'+id).hide('fast');
			jQuery('#poll_options_list'+id).show('slow');
			jQuery('#poll_submit_'+id).show('fast');
		}
	});
	// when vote cast button is clicked.
	jQuery('.poll_submit').click(function(){
		var id = jQuery(this).attr('name');
		var option = jQuery('#polling_'+id).find('input[type="radio"]:checked').val();
		jQuery('#poll_submitBtn'+id).html('<img src="images/frontend/wait.gif" alt="wait ..." />');
		jQuery.ajax({
		   type: "POST",
		   url:  "includes/controllers/ajax.poll.php",
		   data: "action=castvote&id="+id+"&option="+option,
		   success: function(msg){
			 if(msg == 1)
			 {
				 // add hit
				 var initHits  = Number(jQuery('#pollBar_'+option).attr('hits'))+1;
				 var initTotal = Number(jQuery('#pollBar_'+option).attr('totalHits'))+1;
				 jQuery('#pollBar_'+option).attr({'hits':(initHits)});
				 jQuery('#pollBar_'+option).attr({'totalHits':(initTotal)});
				 // change label too
				 jQuery('#span_option_result_'+option).html(initHits);
				 
			 }
			 getOptionGraph();
			 jQuery('#poll_submitBtn'+id).remove();
			 jQuery('#poll_result_list'+id).show('slow');
			 jQuery('#poll_options_list'+id).hide('fast');
		   }
		});
		return false;
	});
	
	dropDownMenu();
});

// ui functions
function getOptionGraph(){
	jQuery('.totalBar').each(function(){
		//var share = jQuery(this).attr('share');
		var hits = jQuery(this).attr('hits');
		var total= jQuery(this).attr('totalHits');
		var share= (hits/total)*100;
		jQuery(this).find('span').css({width:share+'%'});
	});
}

function dropDownMenu() {
	
	jQuery("#menu ul ul").css({display: "none"});
	  
	jQuery("#menu ul li").hover(function() {
		jQuery(this).find('ul:first').css({display: "block", opacity: 0}).stop().animate({ opacity: 1 }, 200); //Slides down when hover the UL
		jQuery(this).children('a').addClass("hovered"); //Adds a hovered class, so you can see the menu path you are following
	}
	,function() {
		jQuery(this).find('ul:first').css({display: "none"}); //Slides up on mouseleave
		jQuery(this).children('a').removeClass("hovered"); //removes the hovered class.
	});
	
}
