$(function(){
	$('#navmenu a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-150px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-300px 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
			}})
		})

		$('#lastNews').list_ticker({
			speed:4000,
			effect:'slide'
		});

	setTimeout(function(){
		$('#slider').nivoSlider({ pauseTime:5000, pauseOnHover:false });
	}, 1000);


	$('a.lightbox').lightBox();
});


	function getDetails(id)
	{

		var id = id;

		jQuery.ajax(
		{
			async :true,
			type :"POST",
			url :"request.php?method=homedepartment&id=" + id + "&rand=" + Math.random(),

			success : function(data)
			{
				var selectedIndex = 0;


				arr  = JSON.decode(data, function(key, value){return key * value});
				cat  = arr.cat;
				work = arr.work;

					$('#dbinfo').html('<br />&nbsp; <b>'+ cat.name +'</b> &nbsp; <br /><br />  عدد الأعمال : ' + cat.totaldata + '<br /><br /><a href="works.php?do=db&id='+id+'&type=">زيارة القسم</a>  | <a href="javascript:WorkBack();">العودة للخلف</a> ' );

                if(work == false || work == null)
                {
                   $('#dbdata').html('<br /><br /><br /><div align="center">عفوا هذا القسم لايحتوي علي أعمال</div>');
                }
                else
                {

					var lidata ;

    				for (var i = 0; i < work.length; i++)
    				{

						if (lidata == null)
						{

	    					lidata = '<li><a href="works.php?do=view&id='+ work[i]['id'] +'">'+ work[i]['title'] +'</a></li>';
                        }
                        else
                        {
							lidata = lidata + '<li><a href="works.php?do=view&id='+ work[i]['id'] +'">'+ work[i]['title'] +'</a></li>';
                        }
    				}

                    $('#dbdata').html('<br /><ul>' +  lidata +'</ul>');
                }




			},
			beforeSend : function(data)
			{
				  $('#homedashboard').slideToggle('slow');
				  $('#dbinfo').html('<br /><br /><br /><img src="images/loading.gif" width="16" height="11" alt="" border="0">');
				  $('#dbdata').html('<br /><br /><br /><div align="center"><img src="images/loading.gif" width="16" height="11" alt="" border="0"></div>');
				  $('#dbd').slideToggle('slow');


			},
			error : function()
			{
					return true;
			}

			});

	}

	function WorkBack ()
	{
      $('#homedashboard').slideToggle('slow');
      $('#dbd').slideToggle('slow');
	  $('#dbinfo').html('');
	  $('#dbdata').html('');
	}




$(document).ready(function() {
 $("#poll").submit(formPollProcess);


  $("#poll-results div").each(function(){
      var percentage = $(this).next().text();
      $(this).css({width: "0%"}).animate({
				width: percentage}, 'slow');
  });

	function formPollProcess(event){
	  event.preventDefault();

	  var id = $("input[@name='poll']:checked").attr("value");
	  id = id.replace("opt",'');

	  $("#poll-container").fadeOut("slow",function(){
	    $(this).empty();

	    votedID = id;
        var rand_no = Math.random();

	    	//$.getJSON("poll.php?vote="+id,loadResults);
	    	$("#poll-result").load("poll.php?id="+votedID + "&do=" + rand_no );


	    });

	}

});




function addToFav() {
 	title = window.document.title;
 	url = window.document.location;

	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{ // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{
		// Opera Hotlist
		return true;
	}



 }

