// JavaScript Document
$.fn.cycle.defaults.timeout = 6000;
function animate_poll(){
	$('.survey_image').each(
		function(){
			var o_width=$(this).attr("width");
			$(this).attr("width","0");
			$(this).animate({width:o_width+"px"},1500);
	});
}
$(function() {
    $('#s3').cycle({
				   fx:'custom',
				   fx: 'scrollDown',
				   sync: 1,
				   easing:'easeOutQuint',
				   cssBefore: {top:0,left: -335,display: 'block','background':'none'},
				   cssAfter: {'background':'none'},
				   animIn:{left:0},
				   animOut:{top: 260},
				   delay: -1000 ,
				   pager:'#nav',pagerEvent:'mouseover',pauseOnPagerHover:true,	pagerAnchorBuilder: function(idx, slide){
            return '#nav li:eq(' + (idx) + ') a';}	});	
	$('#nav li:eq(0) a').css('margin-top','2px');
	$('#news_ticker').cycle({fx:'slideY',speed: 1000,timeout: 4000, next:'#next', prev:'#prev', pause:1,cssAfter: {'background':'none'},cssBefore: {'background':'none'}});
	$('#menu div').css( {backgroundPosition: "-20px 35px"} )
			.mouseover(function(){$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})})
			.mouseout(function(){$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-20px 35px"})
			}})
		})	
	animate_poll();		
	
	var survey;
	$("input[type='submit'][name='survey']").bind('click',survey_click);
	function survey_click(){
		if($(this).val()=="عرض النتائج")
			survey="show_results";
		else
			survey="send_vote";
		}
	function submit_function(e){			
			var option1;
			var survey_id;			
			survey_id= $(this).children("input[name='survey_id']").val();
			option1=$(this).children(".poll_option").children("input[name='check_option'][checked='true']").val();			
			var sub_data="survey_id="+survey_id+"&check_option="+option1+"&survey="+survey;
			//alert(survey);
			$("#survey_overlay").fadeIn(300);
			$.ajax({
			   type: "POST",
			   contentType:"application/x-www-form-urlencoded; charset=windows-1256",
			   scriptCharset:"windows-1256",
			   dataType:"html",
			   processData:false,
			   type:"post",
			   url: "survey/survey.php",
			   data: sub_data,
			   success: function(msg){
				 //alert( "Data Saved: " + msg );
				 
				$("#serv .survey").remove();
				$("#serv #votes").remove();
				$('#serv').append(msg);
				$("#survey_overlay").fadeOut(800);				
				//$('#serv').append(msg);
				//$(this).css("display","none");
				//alert(msg);
				animate_poll();
				$('.survey').bind('submit',submit_function);
				$("input[type='submit'][name='survey']").bind('click',survey_click);
				//alert(msg);
			   }
			 });
			//return false;
			return false;
			
		}
	$('.survey').bind('submit',submit_function);	
	$('#gallery a').lightBox({txtImage:"الصورة",txtOf:"من"});
	$('.search_btn').click(function(){
                $('.search_text_cont form').submit();
            });
	
});
