/* fix browser zooming */
/*
jQuery(document).ready(function(){  
jQuery('#navbar ul.menu li').each(function(){
width_tmp=jQuery(this).width()+28;
jQuery(this).css('padding','8px 0px');
jQuery(this).css('width',width_tmp+'px');
});


jQuery('#footer ul li').each(function(){
width_tmp=jQuery(this).width()+29;
jQuery(this).css('padding','0');
jQuery(this).css('width',width_tmp+'px');
});
});
*/
/*
jQuery(document).ready(function(){
    jQuery(document).bind("contextmenu",function(e){
        return false;
    });
});
*/

ezslide_timer='';
jQuery.fn.ezslide = function ( options ) {
   var defaults = {
            fadeIn  : 1000,
            fadeOut : 100,
            delay   : 3000
        },
        settings = jQuery.extend( defaults, options ),
        $this = this,
        cur = 0,
        fadeIt = function( which ) {
            var li = $this.find('li');

            cur = which = (which >= li.length) ? 0 : which;

            li.fadeOut( settings.fadeOut );
            li.eq( which )
              .delay( settings.fadeOut )
              .fadeIn( settings.fadeIn, function(){
                ezslide_timer=setTimeout(function() { 
                    cur++;
                    fadeIt( cur ); 
                }, settings.delay);
            });

        };

    fadeIt( cur );
};


jQuery(document).ready(function(){								
jQuery.validator.addMethod("notEqual", function(value, element, param) {									
return this.optional(element) || value !== param;
}, "This field is required");


jQuery.validator.addMethod("phoneNumber", function(value, element, param) {									
if(param==false)
return true;
phone_number = value.replace(/\s+/g, ""); 
phone_number=phone_number.replace(/[^a-zA-Z 0-9]+/g,'');
if(!/\D/.test(phone_number) && phone_number.length>6)
{
test_str=phone_number[0]+phone_number[1];
var regExp = new RegExp(test_str,'g'); 
test_phone=phone_number.replace(regExp,'');
if(test_phone.length<2)
return this.optional(element) || false;
var regExp = new RegExp('123456','g'); 
test_phone=phone_number.replace(regExp,'');
if(test_phone.length<6)
return this.optional(element) || false;
for(j=0;j<10;j++)
{
counter=6;
for(i=0;i<phone_number.length;i++)
{
	if(phone_number[i]==j)
	counter++;
	else
	counter--;

if(counter>10)
return this.optional(element) || false;
}
}
return this.optional(element) || /^[0-9\-\ \+]+$/i.test(value);
//return this.optional(element) || true;
}
else
{
return this.optional(element) || false;
}
//return this.optional(element) || value !== param;
}, "Invalid phone number");



								
jQuery("#enq_frm").validate({
rules: {
e_fname:{
required:true,
notEqual:'name'
},
e_mobile:{
required:true,
phoneNumber:true,
notEqual:'mobile'
},
e_comments:{
required:true,
notEqual:'message'
},
e_email: {
required: true,
email: true,
notEqual:'email'
}
}
});

jQuery("#subscribe_frm").validate({
rules: {
s_fname:{
required:true,
notEqual:'name'
},
s_mobile:{
required:true,
phoneNumber:true,
notEqual:'mobile'
},
s_email: {
required: true,
email: true,
notEqual:'email'
}
}
});





});


/* 
$(function(){
	$('#navbar ul.menu a.flyout').each(function(){														
		$(this).next().wrap('<div style="display: none;"/>');		
		$(this).menu({
			content: $(this).next().html(),
			width: 165,
			positionOpts: { posX: 'left', 
			posY: 'bottom',
			offsetX: 0,
			offsetY: 0,
			directionH: 'right',
			directionV: 'down', 
			detectH: false, // do horizontal collision detection  
			detectV: false, // do vertical collision detection
			linkToFront: false },
			flyOut: true
		});
});

	});
*/

jQuery(document).ready(function(){  
jQuery('.coming_soon').click(function(){
alert('Coming Soon');
return false;
});
});


function home_page_slide_show()
{
home_page=false;	
default_image=jQuery("#banner").attr('rel');
jQuery('.menu li a').each(function(){
if(jQuery(this).attr('id')=='current_menu' && jQuery(this).attr('rel')==default_image)
home_page=true;	

if(home_page)
{
}


});
/*
if(home_page)
for(i=0;i<default_image_array.length;i++)
{
jQuery('#banner img').fadeOut('200', function() {
jQuery('#banner img').attr({src:'/images/banners/'+default_image_array[i]});										  									
jQuery('#banner img').fadeIn('600', function() {}); 
});
}
*/
}

jQuery(document).ready(function(){  
								
								
//

jQuery('#banner_img_main').click(function() {			
if(jQuery(this).attr('src')=='/images/banners/summer_header.jpg')
window.location="/news/summer_at_al_ain_raceway_special_offer_buy_1_get_1_free-6";
});




								
//home_page_slide_show();
default_image=jQuery("#banner").attr('rel');
jQuery('.menu li a').mouseover(function() {			
img_name=jQuery(this).attr('rel');

/*(!img_name)
img_name=default_image;
*/

if(!img_name)
{
		img_name=jQuery('#current').attr('rel');
		img_name2=jQuery('#current_menu').attr('rel');
		img_name3=jQuery('#current_footer').attr('rel');
		
		if(!img_name)
		img_name=img_name2;

		if(!img_name)
		img_name=img_name3;						  

		if(!img_name)
		img_name=default_image;						  
}


if(img_name)
if(img_name!='' && '/images/banners/'+img_name!=jQuery('#banner img').attr('src'))
{
jQuery('#banner img').clearQueue();
jQuery('#banner img').stop();

jQuery('#banner img').fadeTo('300','0.1',function() {
jQuery('#banner img').attr({src:'/images/banners/'+img_name});										  									

jQuery('#banner img').fadeTo('300','100', function() {
												   
												   //ie fix
												   if(jQuery(this).css("filter")!='none')
												   document.getElementById('banner_img_main').style.removeAttribute("filter", false); 

												   
												   }); 

});
}
});



jQuery('.menu li a').mouseout(function() {		
		img_name=jQuery('#current').attr('rel');
		img_name2=jQuery('#current_menu').attr('rel');
		img_name3=jQuery('#current_footer').attr('rel');
		
		if(!img_name)
		img_name=img_name2;

		if(!img_name)
		img_name=img_name3;						  

		if(!img_name)
		img_name=default_image;						  

		if(img_name!='' && '/images/banners/'+img_name!=jQuery('#banner img').attr('src'))
		{	
		jQuery('#banner img').clearQueue();
		jQuery('#banner img').stop();
		jQuery('#banner img').fadeTo('300','0.1', function() {
														   

		jQuery('#banner img').attr({src:'/images/banners/'+img_name});																								
		jQuery('#banner img').fadeTo('300','100', function() {
												   if(jQuery(this).css("filter")!='none')
												   document.getElementById('banner_img_main').style.removeAttribute("filter", false); 
		
										 //ie fix
											// if(jQuery(this).css("filter")!='undefined');											 
											 //document.all.banner_img_main.style.removeAttribute("filter", false); 

													 })
		})
		
		}

	  if(jQuery(this).attr('id')=='current')
	  return;
	  if(jQuery(this).attr('id')=='current_menu')
	  return;
	  if(jQuery(this).attr('id')=='current_footer')
	  return;


//if(jQuery(this.parentNode).hasClass('selected'))
//jQuery(this.parentNode).removeClass('selected')
//jQuery(this).animate({ color: '#FFFFFF'},500, function() { });


}

);
});  



jQuery(document).ready(function(){  
if(jQuery('.raceway_ul'))
{
jQuery('.raceway_ul ul.items').hide();
jQuery('.raceway_ul li.current_item ul.children').show();
jQuery('.raceway_ul li.current_item').parent().show();

jQuery(".raceway_ul li.item").toggle(function() { 
  if(jQuery(this).find('ul.items').is(":hidden"))
  jQuery(this).find('ul.items').slideDown('slow');
  else
  jQuery(this).find('ul.items').slideUp('slow');  
    }, function() {  
	if(jQuery(this).find('ul.items').is(":hidden"))
	jQuery(this).find('ul.items').slideDown('slow');
	else
    jQuery(this).find('ul.items').slideUp('slow');
}); 
}
}); 


function includeJs(file) {
        // Handle multiple include attempts
        if(jQuery("script[src='" + file + "']").size() == 0) {
               jQuery('head').createAppend(
                        'script', {
                                type: 'text/javascript',
                                src: file
                        }
                );
        }
}

var req;
function navigate(month,year) {
        var url = "/calendar.php?month="+month+"&year="+year;
        if(window.XMLHttpRequest) {
                req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.open("GET", url, true);
        req.onreadystatechange = callback;
        req.send(null);
}

function callback() {        
        obj = document.getElementById("calendar");
        setFade(0);
        
		if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
                        obj.innerHTML = response;
                        fade(0);
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}



function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
}
function setFade(amt) {
	obj = document.getElementById("calendar");
	amt = (amt == 100)?99.999:amt;
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}




var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 400;
	var speed = 10;
	var timer = 20;
	var endalpha = 75;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,clr,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			tt.style.color = clr;
			tt.style.background=clr;
			
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

