$(document).ready(function(){


/* MENU FIX */

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

$('.menu li ul').css('height',0);
$('.menu li').hoverIntent(
					function(){
						$thisheight = 0;
						$(this).children('ul').children('li').each(function(){
							$thisheight = $thisheight + 1;									
						})
						
						$thisheight = $thisheight * 35;
					
						$(this).children('ul').animate({
							height: $thisheight					
						},500)
					
					}, /* HOVER */
					
					function(){
						
						$(this).children('ul').animate({
							height: 0
						},500)  /* OUT */	
						
						//$(this).children('ul').css("height", 0);
					});


$('#newsletter_return').hide();

	$('#newsletter').submit(function(){
		chkeml = $('#newsletter_email input').checkEmail();
		fname = $('#newsletter_fname input').val();
		sname = $('#newsletter_sname input').val();
		emlval = $('#newsletter_email input').val();
		$('#newsletter_email input').val("").addClass('loading');		
		if(chkeml)		
		{
			$.ajax({
				type: "GET",
				url:"plugs/baf/process.php",
				data: "emailadd=" + emlval + "&fname=" + fname + "&sname=" + sname,
				success: function(data){
					switch(data){
						case "failed":
							message="Error adding to the database";
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input ')
							.removeClass('loading');
						break;
						case "success":
							message="<p style=\"color: #339900; line-height: normal;\">Thank you. Your email has been added to our newsletter database.</p>";
						
							$('#newsletter').slideUp();
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input')
							.val("")
							.removeClass('loading');
						break;
						case "email":
							message="Your email address is already registered";
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input')
							.removeClass('loading');
							$('#newsletter_return').delay(1900).slideUp();
						break;
					}
				}
			});
		}
		else
		{
			$('#newsletter_return').html("Please supply a valid email address.").slideDown();
			$('#newsletter_email input').removeClass('loading');				
			$('#newsletter_return').delay(1900).html("Please supply a valid email address.").slideUp();
		}
		return false;
	});	

	/* INPUT CLEAR */
	
	$(window).bind("load", function(){
			//clear form inputs (add & uses rel attributes for comparison)
			$('.inputClear').focus(function(){
				if(!$(this).attr('rel')) {
					$(this).attr('rel',$(this).val()).val('');
				} else {
					if($(this).val()==$(this).attr('rel')) $(this).val('');
				}
			}).blur(function(){
			   if($(this).val()=="") $(this).val($(this).attr('rel'));
			});

	//GALLERY
	
	//add scrollable
	$('#thumbs').scrollable({circular: true, speed: 1000 , next: ".t_next", prev: ".t_prev"}).autoscroll(6000);
	

	//access jQuery Tools API & globalise gallery variable
	var thumbs=$('#thumbs').data("scrollable");
	var gallery;
	var g_event=0;
	var ti;
	var gallery_images="";
	
	
	//thumbs click event
	$('#thumbs .items>div div').bind('click',function(){
		ti = $('#thumbs .items>div div').index(this);
		
		//if there is no gallery ...
		if(!g_event)
		{
			
			//generate code for large gallery
			$('#thumbs img').each(function(){
				gallery_images+="<div><img width=\"940px\" height=\"600px\" src=\""+$(this).attr('rel')+"\" /><span></span></div>";
			});
			
			// ...crate it
			$('#gallery').append('<div class="scrollable"><div class="items">'+
				gallery_images
			+'</div></div><a class="g_prev" href="#">&#171;</a> <a class="g_next" href="#">&#187;</a>');
			
			// and add scrollable
			$('#gallery').scrollable({
				circular: true,
				next: ".g_next",
				prev: ".g_prev"
			});
			
			//set API variable
			gallery=$('#gallery').data("scrollable");
			
			//set click event for zoom out
			$('#gallery span').bind('click', function(){
				$('#gallery .scrollable').slideUp();
				$('#thumbs .scrollable').slideDown();
				$('#content').slideDown();
				$('#gallery>a').fadeOut();
				$('#thumbs>a').fadeIn();
			});
			g_event=1;
		}
		
		//slide and change gallery image		
		$('#gallery .scrollable').slideDown().animate({height: 600});
		$('#gallery>a').fadeIn();
		$('#thumbs>a').fadeOut();
		
		$('#content').slideUp();
		
		$('#thumbs .scrollable').slideUp();
		gallery.seekTo(ti, 0);
		
	});

	//PRESS RELEASES SCROLLER
	$('#press_releases').cycle({timeout: 10000});
	
	//BRAND SCROLLER
	$('#brands_cont').cycle({timeout: 18000});

});

$(window).load(function() {
		
			
		   var path = location.pathname;
		   $("#menu a[href $='" + path + "']").each(function() {
		       $(this).addClass("current");
		   });
		   
		
		
			if($('#map').length){
			
			
						function setMarkers(map, locations) {
								  		var image = new google.maps.MarkerImage('./media/layout/marker.png',
						
								      	new google.maps.Size(46, 60),
						
								      	new google.maps.Point(0,0),
						
								      	new google.maps.Point(0, 75));
						
								  		var shadow = new google.maps.MarkerImage('./media/layout/marker_shadow.png',
						
								      	new google.maps.Size(200, 200),
								      	new google.maps.Point(0,0),
								      	new google.maps.Point(-12, 45));
						
								  		for (var i = 0; i < locations.length; i++) {
								    		var location = locations[i];
								    		var myLatLng = new google.maps.LatLng(location[1], location[2]);
								    		var marker = new google.maps.Marker({
								        		position: myLatLng,
								        		map: map,
								        		shadow: shadow,
								        		icon: image,
								        		title: location[0],
								        		zIndex: location[3]
								    		});
						
								    		google.maps.event.addListener(marker, 'click', (function(markerArg, html) {
												return function() {
												    infowindow.setContent('<div class="info-window">'+html+'</div>'); 
													infowindow.open(map,markerArg);
												};
											})(marker, location[4]));
								  		} //end for
									} // end setMarkers
			
						var locations = [
								['Lagos: Guru Plaza', 8.885072, 8.525391],
								['Lagos: Park \'n\' Shop &amp; SPAR Lekki', 6.454591, 3.402071],
								['Abuja: Park \'n\' Shop Shopping Centre', 8.407168, 7.915649],
								['Abuja: Ceddi Plaza', 7.591218, 5.756836],
								['Port Harcourt: Park \'n\' Shop', 9.052481, 7.486828]
						];
			
						var myOptions = {
					    	zoom: 6,
					    	center: new google.maps.LatLng(8.917634,8.514404),
					    	mapTypeId: google.maps.MapTypeId.ROADMAP
					  	};
					  	var map = new google.maps.Map(document.getElementById("map"), myOptions);
					                                
					    google.maps.event.addListener(map, 'click', function() {
					    	infowindow.close();
					 
					    });
		
					  	setMarkers(map, locations);
		
					                                
				    var infowindow = new google.maps.InfoWindow({ 
						size: new google.maps.Size(300,75)
					});
		
					
		
					
					
					} //eo if $('#map')
				}); // eo window.load
				
});

/* Author: 

*/

	//$('#header').load('template/header.html');
	//$('#footer_container').load('template/footer.html');


	/*$("#baf").submit(function(){
		name = $('#baf_name').val();
		email = $('#baf_email').val();
		func = "baf";
	
		$.ajax({
			type: "POST", 
			url: "php/ajax.php", 
			data: "func="+func+"&name="+name+"&email="+email, 
			success: function(data){
				if(data == '1'){
					$(this).children('span').html('Thank You, You Will Recieve Confirmation Via Email Shortly');
				} else {
					$(this).children('span').html('There Was A Problem With Your Request Please Try Again');
				}
			}				
		});
	
		
		return false;
	});*/

/*//MAIN SCROLL
	$("#images").scrollable({		
		circular:true,
		easing:"swing",
		speed:450
	});*/
	

//$('#images').rotary();


//SECONDARY SCROLL
/*$('#images').rotary({
	auto: {interval:4000},
	changer: 'img',

	ext: {
		queue:false,
		duration:500,
		easing:'swing'
	},
	control: {
		ind: {
			element: $('#i_c a'),
			binding: 'click',
			onclass: 'cur'
		}
	}
});*/
























