	$(document).ready(
		function(){
			
			$('#pollForm').submit(function(){
				/*alert($(this).serialize().substring(5));return false ;*/
				$.ajax({
					url:$(this).attr('action'),
					type:"POST",
					async: true,
					data: {
					 poll : $(this).serialize().substring(5)
					},
					beforeSend: function (XMLHttpRequest) {
					},
					success: function(html){
					 $("#votesContainer1").animate({marginLeft:"-200px" ,opacity :'0'}, "10000" , function(){
						 $("#votesContainer2").html(html).delay('100').animate({marginLeft:"10px" ,opacity:'1'}, "1000000");		 
						 
					 })	
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
					}
				});	
			   return false ;
				
			})
			
			
			
		   if($('#panoramasContainer').length){
			   $("#panoramasContainer").mouseover(function(){
				   $(".take-ourTour-1").animate({marginLeft:"-235px" ,opacity :'0',width:'0px'}, "10000" , function(){
					   $(".take-ourTour-2").delay(100).animate({marginLeft:"0px" ,opacity :'1',width:'235px' }, "10000");		 
				   })
					 	 
			   }).mouseleave(function(){
				   if($('.take-ourTour-1').css('opacity') == 0){
				    $(".take-ourTour-2").animate({marginLeft:"-235px" ,opacity :'0',width :'0px'}, "10000" , function(){
						 $(".take-ourTour-1").delay('100').animate({marginLeft:"0px" , opacity : '1' ,width:'235px'}, "10000");		 
						 
					})
						
				   }
			   })
			   			   
		   }	
			
			
			 $('.take-ourTour-2').find('a').each(function() { 
				 $(this).click(function(){
				       window.open($(this).attr('href'),"mywindow","menubar=1,resizable=1,width=1280,height=768");
				       $(".take-ourTour-2").animate({marginLeft:"-235px" ,opacity :'0',width :'0px'}, "10000" , function(){
							 $(".take-ourTour-1").delay('100').animate({marginLeft:"0px" , opacity : '1',width :'235px'}, "10000");		 
							 
						})
				       return false ;
				 }) 
			 });
			 	 	
		   	
		  	
			// projects menu
			if($('.main-top-menu').children('ul').children('li').length)new buildProjectsMenu($('.main-top-menu').children('ul').children('li'));
			
			// left menu	
			if($('#leftMenu').children('ul').length)new buildLeftMenu().init($('#leftMenu'));
			
			// right menu
			if($('.right-menu').length)new buildRightMenu($('.right-menu'));


			// news bar
			// new newsBar();
			$('marquee').marquee('pointer').mouseover(function () {
				$(this).trigger('stop');
			}).mouseout(function () {
				$(this).trigger('start');
			}).mousemove(function (event) {
				if ($(this).data('drag') == true) {
					this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
				}
			}).mousedown(function (event) {
				$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
			}).mouseup(function () {
				$(this).data('drag', false);
			});
			
			
			// internal pages
			if($('.innerpages-container').length)	$('.innerpages-container').buildOccurdionInternalPages();
			
			if($('form.jotform-form')) new jotFrom().init({form : $('form.jotform-form')});
			
			if($('#calendarContainer').length)
				$('#calendarContainer')
						.find('.calendar-events-day')
						.mouseover(
							function(){
																
								var containerLeft 	= $(this).closest('table').offset().left;
								var containerWidth 	= $(this).closest('table').width();
								
								var itemLeft 		= $(this).closest('td').offset().left;
								
								$(this).children('div').css({'left': (containerLeft - itemLeft - 1 ) + 'px', width : containerWidth + 1 + 'px' });
							});
						
						
						
						
			if($('a[title="membership register now"]'))$('a[title="membership register now"]').addClass('membership-button');
			
			if($('#homePageSlider').length)$('#homePageSlider').homePageSlider();
			
		});
	
	
		$.fn.extend({				
					
				buildOccurdionInternalPages : function(){
						
					$(this)
						.find('li').each(
								function(index, element){
									$(this).children('a')
										.attr('href', '#'+$(this).children('a').attr('href'))
										.click(
											function(){
												var container = $(this).parent().addClass('active').find('span').text('-').closest('li');
												container.children('div').slideDown('slow');												
												container.nextAll('li').each(function(){$(this).removeClass('active').find('span').text('+').closest('li').children('div').slideUp();});
												container.prevAll('li').each(function(){$(this).removeClass('active').find('span').text('+').closest('li').children('div').slideUp();}); 
											}
										).next('div').hide();
								});
						
					if(location.hash.length)
						$(this).find("a[href*='"+location.hash+"']").click();
					else
						if($(this).find('li.active')){$(this).find('li.active').find('a').click();}
						
						
						
				}
			
		});
	
	
	
	
	
	
		function newsBar(obj){
			
		}
		
		
		
		function buildRightMenu(obj){		
           	var timeOutRightObj = null;
			var RMenu = obj;
			
			
			
			RMenu.children('.menu-button')
					.click(
						function(){
							RMenu.removeClass('closed'); 
						}
						
					).mouseout(
						function(){						
							timeOutRightObj = setTimeout(function(){RMenu.addClass('closed');}, 500);	
						}
						
					).mousemove(
						function(){
							if($(this).parent().hasClass('closed'))RMenu.removeClass('closed'); 
							clearTimeout(timeOutRightObj);
						}				
						
					);
				
				RMenu.children('ul')
					.click(
						function(){
							$(this).prev().click();
						}
						
					).mouseout(
						function(){					
							$(this).prev().mouseout();						
						}
						
					).mousemove(
						function(){						
							$(this).prev().mousemove();
						}				
						
					).find('ul').find('li').click(function(){ $(this).parent().children('li').removeClass('active'); $(this).addClass('active'); });
				
				
				
				//  close menu
				RMenu.addClass('closed');
				
			
	
			

				
		}
		
		

		function buildProjectsMenu(obj){
		
           	var timeOutPMenuObj = null;
			var PMenu = obj;	
			
			PMenu
				.click(
					function(){
						PMenu.children('ul').css({'visibility' : 'visible', 'left' : "0px"});
					}
				).mouseout(
						function(){						
							timeOutPMenuObj = setTimeout(function(){PMenu.children('ul').css({'visibility' : 'hidden', 'left' : "-10000px"});}, 500);	
						}
					).mousemove(
						function(){
							clearTimeout(timeOutPMenuObj);
						}				
					);		
			
			
		}


		function buildLeftMenu(){
			this.timeOutObjs = new Array();
			this.container 	= null;	
			this.prefix		= "MM";
			this.groups 	= new Array();
			this.activeList = 0;
			this.maxZIndex	= 4000;
			this.activeZIndex= this.maxZIndex;
			$this 			= this;
			
			this.reset = function(){
				this.activeZIndex= this.maxZIndex;	
			}
						
			this.prepare = function(subMenu){

				var subMenuId 	= subMenu.attr('id');
				var group		= [];
				var li			= $('li[rel="'+subMenuId+'"]');
				var ul			= subMenu;

				group[0] = subMenuId;
				while(li.is('li')){
					ul			= li.closest('ul');
					subMenuId 	= li.closest('ul').attr('id');					
					li 			= $('li[rel="'+subMenuId+'"]');

					if(subMenuId != '') group[group.length]	= subMenuId;

				}

				$this.groups[subMenu.attr('id').split('-')[1]] = group;//.reverse();

			}
			
			this.interval = function(){
				
					/*
					setInterval(function(){
										
						if($this.groups.length)	{
							for(var item=0; item < $this.groups.length; item++){
								if($this.groups[item] != undefined){
									for(x=0; x < $this.groups[item].length; x++){
										//console.info($this.timeOutObjs+"  = "+$this.groups[$this.activeList][item]);
										if(jQuery.inArray( $this.groups[item][x], $this.groups[$this.activeList] ) == -1){
											$('ul#'+$this.groups[item][x]).removeClass('visible').animate({'left' : "10px"}, 500, function(){$(this).css({'visibility' : 'hidden'}); });
											$('li[rel="'+$this.groups[item][x]+'"]').removeClass('over');
										}
									}
									
								}
							}
						}	
						
					}, 1000);	
					*/
				
			
			}
			
			this.hide = function(activeList){
				$this.timeOutObjs[activeList] 
						= setTimeout(function(){
										
											if($this.groups[activeList] != undefined){
												for(x=0; x < $this.groups[activeList].length; x++){	
													//if(jQuery.inArray( $this.groups[activeList][x], $this.groups[$this.activeList] ) == -1){
														$('ul#'+$this.groups[activeList][x]).removeClass('visible').animate({'left' : "10px"}, 500, function(){$(this).css({'visibility' : 'hidden'}); });
														$('li[rel="'+$this.groups[activeList][x]+'"]').removeClass('over');
													//}
												}
											}
										
										}, 500);
			}
			
			this.show = function(activeList){
				
			}
			
			this.init = function(obj){
				this.container = obj;
				
				this.container.find('ul').prepend('<li class="first"><div><p class="l"></p><p class="r"></p></div></li> <li class="last"><div><p class="l"></p><p class="r"></p></div></li> <li class="left"><div></div></li> <li class="right"><div></div></li>');
				
				this.container.children('.main-menu').children('li[rel|="'+$this.prefix+'"]').mouseover(function(){ ++$this.activeZIndex; /*$this.reset();*/});
				
				this.container.children('.main-menu').find('li[rel|="'+$this.prefix+'"]').each(
					function(){
						
						var id 		= $(this).attr('rel');
						var submenu	= $('ul#'+id);						
						var activeList = id.split('-')[1];						
						$this.prepare(submenu);
						
						$(this)
							.mouseout(
								function(){	
									$this.hide(activeList);									
								}
							
							).mouseover(
								function(){
									
									$this.activeList = activeList;
									//--$this.activeZIndex;
									
									
									var left 	= parseInt($(this).width()) + parseInt($(this).position().left) + parseInt($(this).parent().position().left) + 10;
									var top 	= $(this).position().top;
									
									DLeft = left < 10 ? 10 : parseInt($(this).position().left);
									
									if($('ul#'+id).css('visibility') == 'hidden')
									/*if(!$('ul#'+id).hasClass('visible'))*/
									$('ul#'+id).stop().css({"visibility" : "visible", "top" : top, "left":DLeft, 'z-index' : $this.activeZIndex}).addClass('visible').animate({"left":left});
									$('li[rel='+id+']').addClass('over');
								}
							
							).mousemove(
								function(){
									$this.activeList = activeList;
									//console.info(activeList);
									clearTimeout($this.timeOutObjs[activeList]);
								}
							
							);
						
						
						submenu.mouseout(
								function(){	
									$this.hide(activeList);									
								}
							
							).mouseover(
								function(){
									$this.activeList = activeList;
									
								}
							
							).mousemove(
								function(){
									$this.activeList = activeList;
									//console.info(activeList);
									clearTimeout($this.timeOutObjs[activeList]);
								}
							
							);
						
					}
				);
				
				
				$('ul[id|="'+$this.prefix+'"]').appendTo($this.container);
				this.interval();
			}
			
			
			
			
			return this;
			
		}










	function jotFrom (){
		this.form = null;
		this.itemsToValidate = null;
		this.validationNames = Array('email','required','numeric','mobile','url');
		this.errorMessage = '<div class="form-error-message"><img align="left" style="margin-right:5px;" src="'+$imagePath+'exclamation-octagon.png"> This field is required.<div class="form-error-arrow"><div class="form-error-arrow-inner"></div></div></div>';
		me = this;
		
		this.init = function(data){
			this.form = data.form;	
			
			this.form.find('input,select,checkbox,textarea').focus( function(){ $(this).closest('li').addClass('form-line-active') }).blur(function(){$(this).closest('li').removeClass('form-line-active');});
			
			this.itemsToValidate = this.form.find('[class*="validate"]');
			
			
			this.itemsToValidate.each(
					function(){						
							me.prepareElement($(this));
						
						});
			
			this.form.submit(
					function(){
							return me.isValid();
						});
			
			
		}
		
		this.prepareElement = function(item){
						
			if($(item).is('input[type="text"]') && $(item).hasClass('form-textbox')){
				$(item)	
					.focus(
						function(){
							$(this).closest('li').find('form-error-message').remove();	
						
						})
					.blur(
						function(){
							
							if(!me.isValidElement($(this))){	
								if(!$(this).closest('li').find('.form-error-message').length)
									$(this).after(me.errorMessage);
									
								$(this).closest('li').addClass('form-line-error');	
									
							}else{
								$(this).closest('li').removeClass('form-line-error').find('.form-error-message').remove();	
							}
							
						});
				
				
			}else if($(item).is('input[type="tel"]') && $(item).hasClass('form-textbox')){
				$(item)	
					.focus(
						function(){
							$(this).closest('li').find('.form-error-message').remove();	
						
						})
					.blur(
						function(){							
							if(!me.isValidElement($(this))){								
								if(!$(this).closest('div').find('.form-error-message').length)
									$(this).closest('div').append(me.errorMessage);
									
								$(this).closest('li').addClass('form-line-error');	
								
							}else{
								$(this).closest('li').removeClass('form-line-error').find('.form-error-message').remove();	
							}
							
						});				
				
			}
			
			
			
			
		}
		
		this.isValid = function(){
			
			var isValid = true;
			this.itemsToValidate.each(
					function(){
							if(!me.isValidElement($(this))){	
								isValid = false;
								$(this).blur();
							}
						
						});
			
			return isValid;
		}
		
		this.isValidElement = function(item){			
		
			var validate = $(item).attr('class').toLowerCase().replace(/.*validate\[(.*)\].*/,'$1').split(/\s*,\s*/);

			var regex = null;
			var value = $(item).val();
			var result = true;
			for(v in validate){
				
				if($.inArray(validate[v], me.validationNames) > -1){
					switch (validate[v]){
						case "required":
							regex = new RegExp(/^\S(.*)+$/);
							break;
	
						case "numeric":
							regex = new RegExp(/^[\d\-\.\s]+$/);
							break;
	
						case "email"  :
							regex = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);
	;						break;
	
						case "mobile" :
							regex = new RegExp(/^[\d]{10}$/);
	;						break;
						
						case "url" 	  :
							regex = new RegExp(eval('/^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$/'));
	;						break;
	
						default	      :
							try{
								// regex = new RegExp(eval(validate[v]));								
							}catch(e){alert($(this).attr('name')+" regex error ");}
							break;
	
					}
					
					result = value.match(regex);
					if(result == false || result == null)return result;
					
				}
				//alert(result);
				
			}
			
			return true;
		}
		
		
	}













	function homePageSlider(){
		
		this.element 	= null;
		this.interval	= null;
		this.delay		= 2000;
		this.speed	 	= 1000;
		this.step		= 0;
		this.leftArrow	= '';
		this.rightArrow	= '';
		this.itemsContainer= '';
		this.DMarginLeft= 0;
		this.activeImage= '';
		this.active 	= false;
		this.containerHeight = 0;
		this.minItemsToStart = 3;
		
		var me = this;
		
		this.init 		= function(settings){
			this.element 		= settings.element;
			this.speed			= settings.speed != undefined ? settings.speed : this.speed;
			this.delay			= settings.delay != undefined ? settings.delay : this.delay;
			this.itemsContainer	= this.element.parent();			
			this.minItemsToStart= settings.minItemsToStart != undefined ? settings.minItemsToStart : 3;
			
			this.element.children('li')
				.each(
					function(){
							var height = $(this).height();
							if(height > me.containerHeight)  me.containerHeight = height;
							$(this).css({"opacity": 0, top:"-100%"}).mouseover( function(){me.stop();} ).mouseout(function(){me.start();});
						}
					);
			
			try{
				this.element.children('li:first').addClass('active').css({"opacity": 1, top:"0px"}).get(0).style.removeAttribute('filter');
			}catch(e){}
			
			this.element.height(this.containerHeight * 1.5);
			if(this.element.children('li').length >= this.minItemsToStart){
				this.start();
				
				//this.element.mouseover(function(){me.stop();}).mouseout(function(){me.start();});
				
			}
			
		}
		
		this.start 		= function(){
			this.interval = setInterval(function(){ me.moveDown(); }, me.delay);
		}
		
		this.stop 		= function(){
			clearInterval(me.interval);
		}
		
		this.moveDown  	= function(){
			
			var activeElement = this.element.children('li.active');			
			var elementToShow = activeElement.length && activeElement.next('li').length ? activeElement.next('li') : this.element.children('li:first');
			
			var height = parseInt(elementToShow.height());
			
			elementToShow.css({"top" : "-" + height + 'px'}).animate({top : "0px", opacity:1}, me.speed, function(){$(this).addClass('active'); try{$(this).get(0).style.removeAttribute('filter');}catch(e){} });
			
			if(activeElement.length)activeElement.animate({top : (height + 50) + 'px', opacity:0}, me.speed, function(){$(this).removeClass('active');});			
			
			
		}
		
		return this;
	}



	$.fn.extend({
			homePageSlider:function(){
				new homePageSlider().init(
							{
								element 		: $(this),
								speed			: 1000   ,
								delay			: 6000	 ,
								minItemsToStart	: 2
							}
					  );
				}
				
		});


/*

	$.fn.extend({
				
			// projects menu events
			projectsMenu : 
			
			
			
	
	});
	
	
	*/
