/******************** <<<<<<<<<< [VERSION 3.0] >>>>>>>>>> *******************
	<summary>
		Created By		:	Asif Ahmed
		Company			:	WebOnRetail Technologies
		Creation Date	:	07 february 2011 
		Date Modified	:	08 february 2011
		Dependencies	:	None
		Website			:	www.webonretail.com
		Email			:	asif.ahmed01@gmail.com
		Copyright (c) 2011 webonretail Technologies. All rights reserved.
	</summary>
/**************************************************************************/

// Default configuration properties.
var defaults = {
	IsActiveMenu:false
};
$.fn.extend({
	fadeInFadeOutHoverEffect: function(opacity) {
		$(this).hover(function(){
			$(this).stop().fadeTo('slow', opacity/100);
		},function(){
			$(this).stop().fadeTo('slow', 1.0);
		});
		return false;
	},
	lavaMenu: function(activeClass) {
		var alement = $(this), isactive = false;
		if($(alement).parent().find('div#lavaMenu').length == 0)	{
			$(alement).parent().append("<div id='lavaMenu' class='lavaMenu'>&nbsp;</div>");
		};
		var $lavaMenu = $(alement).parent().find('div#lavaMenu');
		$(activeClass).parents().each(function(index) {
			if($(alement).attr('lavaMenu') == $(this).attr('lavaMenu'))	{
				$position = $(this).position();        
				$lavaMenu.css({ 
					//left:$position.left,
					top:$position.top,
					width:$(this).width(),
					height:$(this).height()
				});
				$lavaMenu.show();
				$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
				isactive = true;
				return false;
			};
		});
		
		if(!isactive) $lavaMenu.stop(true, false).animate({left:'0px'}, {duration: 500, specialEasing: {left: 'swing'}, complete: function() {$lavaMenu.hide();}});		
		
		$(alement).hover(function(){
			$position = $(this).position();        
			$lavaMenu.css({ 
				//left:$position.left,
				top:$position.top,
				width:$(this).width(),
				height:$(this).height()
			});
			$lavaMenu.show();
			$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
			//$lavaMenu.stop(true, false).animate({ left: $position.left + "px" }, 1000);
		},function(){
			$(activeClass).parents().each(function(index) {
				if($(alement).attr('lavaMenu') == $(this).attr('lavaMenu'))	{
					$position = $(this).position();        
					$lavaMenu.css({ 
						//left:$position.left,
						top:$position.top,
						width:$(this).width(),
						height:$(this).height()
					});
					$lavaMenu.show();
					$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
					isactive = true;
					return false;
				};
			});
			if(!isactive) $lavaMenu.stop(true, false).animate({left:'0px'}, {duration: 500, specialEasing: {left: 'swing'}, complete: function() {$lavaMenu.hide();}});		
		});
		return false;
	},
	lightbox: function() {
		$(this).bind('click',function(){
			jQuery.lightboxAbsoluteCenter($(this).attr('rel'));			
			jQuery.lightboxOverlay($(this).attr('rel'));
		});
		return false;
	},
	lightboxpopup: function() {
		$(this).bind('click',function(){
			jQuery.lightboxAbsoluteCenter($(this).attr('rel'));			
			jQuery.lightboxContainer($(this).attr('rel'));
		});
		return false;
	},
	myMethod: function() {
		alert('hey! function is working!!!') ;
	}
});
//jQuery("div").myMethod();  
$.extend({ 
	activeMenu: function(navigationclass, activeclass) {
		var href, currentfilename, winlocation, pathname;
		pathname = window.location.pathname; 
		winlocation = $(location).attr('href').length > 0 ? $(location).attr('href') : window.location.href;
		currentfilename= winlocation.split('/');
		currentfilename = currentfilename[currentfilename.length - 1].split('.');
		currentfilename = currentfilename.length > 1 ? currentfilename[currentfilename.length - 2].toLowerCase() : currentfilename[currentfilename.length - 1].toLowerCase();
		
		$(navigationclass).each(function(index) {
			if ($(this).attr("href") !== undefined) {
				href = $(this).attr("href").split('/').length > 0 ? $(this).attr("href").split('/') : $(this).attr("href").split("\\");
				href = href.length > 0 ? href[href.length-1] : $(this).attr("href");
				href = href.split('.');
				href = href.length > 1 ? href[href.length - 2].toLowerCase() : href[href.length - 1].toLowerCase();
				
				if((currentfilename == href) || ((href == 'default' || href == 'index' || href == 'intro') && currentfilename.length == 0 )) {
					 $(this).removeClass(jQuery.trim(navigationclass.replace('.', ''))).addClass(jQuery.trim(activeclass.replace('.', '')));
					if(!defaults.IsActiveMenu) $(this).attr("href", "javascript:void(0);");
				};
			};
		});
		return false;
	},
	fadeInFadeOutHoverEffect: function(e, opacity) {
		$(e).hover(function(){
			$(this).stop().fadeTo('slow', opacity/100);
		},function(){
			$(this).stop().fadeTo('slow', 1.0);
		});
		return false;
	},
	lavaMenu: function(e, activeClass) {
		var isactive = false;
		if($(e).parent().find('div#lavaMenu').length == 0)	{
			$(e).parent().append("<div id='lavaMenu' class='lavaMenu'>&nbsp;</div>");
		};
		var $lavaMenu = $(e).parent().find('div#lavaMenu');
		$(activeClass).parents().each(function(index) {
			if($(e).attr('lavaMenu') == $(this).attr('lavaMenu'))	{
				$position = $(this).position();        
				$lavaMenu.css({ 
					//left:$position.left,
					top:$position.top,
					width:$(this).width(),
					height:$(this).height()
				});
				$lavaMenu.show();
				$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
				isactive = true;
				return false;
			};
		});
		
		if(!isactive) $lavaMenu.stop(true, false).animate({left:'0px'}, {duration: 500, specialEasing: {left: 'swing'}, complete: function() {$lavaMenu.hide();}});		
		
		$(e).hover(function(){
			$position = $(this).position();        
			$lavaMenu.css({ 
				//left:$position.left,
				top:$position.top,
				width:$(this).width(),
				height:$(this).height()
			});
			$lavaMenu.show();
			$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
		},function(){
			$(activeClass).parents().each(function(index) {
				if($(e).attr('lavaMenu') == $(this).attr('lavaMenu'))	{
					$position = $(this).position();        
					$lavaMenu.css({ 
						//left:$position.left,
						top:$position.top,
						width:$(this).width(),
						height:$(this).height()
					});
					$lavaMenu.show();
					$lavaMenu.stop(true, false).animate({ left: $position.left + "px" });
					isactive = true;
					return false;
				};
			});
			if(!isactive) $lavaMenu.stop(true, false).animate({left:'0px'}, {duration: 500, specialEasing: {left: 'swing'}, complete: function() {$lavaMenu.hide();}});		
		});
		return false;
	},
	lightboxpopup: function(e) {
		$(e).bind('click',function(){
			jQuery.lightboxContainer($(this).attr('rel'));
		});
		return false;
	},
	lightbox: function(e) {
		$(e).bind('click',function(){
			jQuery.lightboxOverlay($(this).attr('rel'));
		});
		return false;
	},
	lightboxOverlay: function(e) {
		if($(e).parent().find('div#overlay[overlay=overlay]').length == 0)	{
			$(e).parent().append("<div id='overlay' class='overlay' overlay='overlay'></div>");
		};
		
		var $overlay = $(e).parent().find('div#overlay[overlay=overlay]');
		var $opacity = $overlay.css('opacity');
		$overlay.css({opacity: 0.0}).dequeue().stop().animate({opacity:$opacity}, 1000, function() { jQuery.lightboxContainer(e); });
	},
	lightboxContainer: function(e) {
		if($(e).css('visibility') == 'hidden')	{
			$detailwindow = $('[detailwindow=' + $(e).attr('detailwindow') + ']');
			$detailwindow.each(function(index) {
				if($(e).attr('detailwindow') == $(this).attr('detailwindow'))	{
					$(this).css({'visibility':'hidden'});
				};
			});
			
			if($(e).find('a#closebutton').length == 0)	{
				$(e).append("<a id='closebutton' class='closebutton' href='javascript:void(0);'>&nbsp;X&nbsp;</a>");
			};
			
			$(e).find('a#closebutton').bind("click", function(){
				$(this).parent().css({opacity: 1.0}).dequeue().stop().animate({opacity: 0.0}, 1000, function() { $(this).css({'visibility':'hidden'}); });
				var $overlay = $(e).parent().find('div#overlay[overlay=overlay]');


				if($overlay.length > 0)	{
					$overlay.css({opacity: $overlay.css('opacity')}).dequeue().stop().animate({opacity: 0.0}, 1000, function() { $overlay.remove(); });
				};
			});
			$(e).css({'visibility':'visible'});
			$(e).css({opacity: 0.0}).dequeue().stop().animate({opacity: 1.0}, 1000);
		}
	},
	lightboxAbsoluteCenter: function(e) {
		var popMargTop = ($(e).height() + 80) / 2;
		var popMargLeft = ($(e).width() + 80) / 2;
		
		//Apply Margin to Popup
		$(e).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft,
			'position' : 'fixed',
			'left' : '50%',
			'top' : '50%'
		});
		return false;
	},
	myMethod: function() {
		alert('hey! method is working!!!') ;
	}
});  
//jQuery.endrequesthandler(); 
//
//jQuery(document).ready(function() {
//	jQuery.fadeInFadeOutHoverEffect('.headerNavigation', 60);
//	jQuery(".headerNavigation").fadeInFadeOutHoverEffect(40);  
//	jQuery.lavaMenu('div[lavaMenu=navGroup1]','.headerNavigationHover');
//	jQuery('div[lavaMenu=navGroup1]').lavaMenu('.headerNavigationHover');  
//								
//	jQuery.activeMenu('.bitsNavigation','.bitsNavigationHover');
//	jQuery('#apDivEasySlideShowOne').easySlideShow({
//		showcontrolbutton:false,
//		autoplay:true,
//		animationspeed:1000,
//		effect:'random',
//		mode:'smooth',
//		randomEffect:new Array('left', 'right')
//	});
//});
