var slowSpeed = 500;
var fastSpeed = 200;

jQuery(document).ready(function() {
	var defImageLoadTemplArray = new Array("mtpl1","mtpl2","mtpl3","mtpl4","mtpl5","mtpl6","mtpl7","mtpl8","mtpl9","mtpl10");
	defaultOnloadWrapper(defImageLoadTemplArray,'#wrapper','.mtpl27');
	//Changes the Facebook link in the site if accessed by lecoqsportif.nl
	changeFacebookLink();
});




   /**
    * Changes the Facebook link in the site if accessed by lecoqsportif.nl
    * @author M K Nisar Uddin <nisar@w3industries.in>
    * @param none
    * @return none
    */
    function changeFacebookLink(){
    	var pageUrl = window.location.href;
    	if (pageUrl.indexOf("lecoqsportif.nl") != -1){
    		jQuery(".mtpl7 a").attr("href","http://www.facebook.com/CREA_BEA#!/pages/Le-Coq-Sportif-Nederland/133539050088923");
    		jQuery('a[href="http://www.facebook.com/#!/be.LeCoqSportif"]').attr("href","http://www.facebook.com/CREA_BEA#!/pages/Le-Coq-Sportif-Nederland/133539050088923");
    	}
    }
   

	/**
	 * Don't know who has written this function. Absolutely no useful comments.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param defImageLoadTemplArray
	 * @param name
	 * @param notclass
	 * @return
	 */
	function defaultOnloadWrapper(defImageLoadTemplArray,name,notclass){
		
		// Loader
		//imgs = jQuery('#wrapper img');
//		imgs = jQuery('#wrapper .img_wrapper img');
		imgs = getParentObject(name);
		imgArray = new Array();
		
		var groupMinJsStr = "";
		var groupMinCssStr = "";
		// Initialising hover effect
		allMtplArray = defImageLoadTemplArray;
		
		loadWorkImages(imgs);
	}
	
	/**
	 * Don't know who has written this function. Absolutely no comments.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param name
	 * @return
	 */
	function getParentObject(name){
		return jQuery(name+' .img_wrapper img');
	}
	
	/**
	 * Don't know who has written this function. Absolutely no comments.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param target
	 * @return
	 */
	function loadWorkImages(target){
		target.css({'opacity' : .2});
		var loadArray = new Array();
		target.each(function(i){
			loadArray[i] = jQuery(this).attr('src');
			var loadtarget = jQuery(this).parent();
			var parent = jQuery(this).parent().parent();
			var loader = jQuery(this).parent().parent().parent();
			
			var imgWidth = jQuery(this).attr('width');
			var imgHeight = jQuery(this).attr('height');
			
			//alert("imgWidth:  "+imgWidth+"imgHeight:  "+imgHeight)
			jQuery(this).remove();
//			jQuery(this).attr('src','');
			parent.css('opacity',0);
			loader.append('<img src="'+ W3FE_BASE_URL+'/prototype/_images/loader.gif" class="loader" />');
			
			loadImage(parent, loadtarget, loadArray[i]);
		});

		target.css({opacity: 1});
	}
	/**
	 * Don't know who has written this function. Absolutely no useful comments.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param parent
	 * @param target
	 * @param url
	 * @return
	 */
	// loading Images
	function loadImage(parent,target,url){
					
		/*parent.css('opacity',0);			
		jQuery(target).html(jQuery('<img />').attr('src', url));
		jQuery(target).parent().parent().children('img.loader').each(function(){jQuery(this).remove();});
		parent.animate({opacity: 1}, 300);*/
		
		/**
		 * Dynamically creating img tag to get the original block images after loader is removed
		 */
		var image = new Image();
		image.onload = function() {
		    parent.css('opacity',0);
		    target.prepend(jQuery(this));
		    jQuery(target).parent().parent().children('img.loader').each(function(){jQuery(this).remove();});
			parent.animate({opacity: 1}, 300);
			image.alt = "";
			/*image.width = imgWidth;
			image.height = imgHeight;*/
		};
		image.src = url;
		
	
		
		/*jQuery('<img />')
			.attr('src', url)
			.load(function(){
				parent.css('opacity',0);			
				target.prepend(jQuery(this));
				jQuery(this).parent().parent().parent().children('img.loader').each(function(){jQuery(this).remove()});
				parent.animate({opacity: 1}, 300);
				jQuery(this).attr("alt", "");

		}).error(function(){
		});*/
	}
	/**
	 * Don't know who has written this function. Absolutely no comments.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param c_name
	 * @param value
	 * @param expiredays
	 * @return
	 */
	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	/**
	 * Don't know who has written this function. No comments for function.  Don't know where it has been used also. Added this comment to atleast differentiate between different functions. -- GK
	 * 
	 * @param check_name
	 * @return
	 */
	function Get_Cookie( check_name ) {
		// first we'll split this cookie up into name/value pairs
		// note: document.cookie only returns name=value, not the other components
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f

		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );


			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

			// if the extracted name matches passed check_name
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
	}
	
	/**
	 * For columnizing footer menu. Menus will be rendered from right to left.
	 */
	jQuery(document).ready(function(){
		remainingHeight = '';
		prevRemainingHeight = '';
		column = '';
		defaultHeight = 300;
		prevHeight = '';
		footerDivHeight = jQuery('#footer').height();
		
		jQuery('#footer>div>div').each(function(index){
			catHeight = jQuery(this).height();
//			alert('B4'+catHeight);
			catHeadHeight = jQuery(this).children('h2').height();
			if(jQuery(this).children('ul').length > 0){
				if(jQuery(this).children('ul').children('li').length > 0){
					catHTML = jQuery(this).html();
					remainingHeight = defaultHeight - catHeight;
//					alert('Remaining:'+remainingHeight);
					if(jQuery(this).prev().length > 0){
						prevHeight = jQuery(this).prev().height();
						prevHTML = jQuery(this).prev().html();
						prevRemainingHeight = defaultHeight - prevHeight;
					}
					if(jQuery(this).next().length > 0){
						nextHeight = jQuery(this).next().height();
						nextHTML = jQuery(this).next().html();
					}
//					alert('Next:'+nextHeight);
					if(catHeight < remainingHeight && nextHeight < remainingHeight){
						if(prevHeight < defaultHeight && catHeight < prevRemainingHeight){
							jQuery(this).prev().append(catHTML);
							jQuery(this).css({'float':'right'});
							jQuery(this).remove();
						}else if(catHeight < remainingHeight && nextHeight < remainingHeight){
							jQuery(this).css({'float':'right'});
//							alert('After'+jQuery(this).height());
							if(jQuery(this).next().length > 0){
								jQuery(this).append(nextHTML);
								jQuery(this).next().remove();
								nextHTML = '';
							}
						}
						else{
							jQuery(this).css({'float':'right'});
						}
					}else{
						jQuery(this).css({'float':'right'});
					}
				}
			}
			else{
				jQuery(this).css({'float':'right'});
			}
		});
	});
	
	
	/**
	 * Click to activate IE fix code
	 */
	var bo_ns_id = 0;

	function startIeFix(){
		
	  if(isIE()){
	    document.write('<div id="bo_ns_id_' + bo_ns_id + '"><!-- ');
	    
	  }
	}

	function endIeFix(){
	  if(isIE()){
		  
	    document.write('</div>');
	    var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
	    var theCode = theObject.innerHTML;
	    theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"));
//	    alert(theCode);
//	    alert('from IE');
	    document.write(theCode);
	  }
	}

	function isIE(){
	  // only for Win IE 6+
	  // But not in Windows 98, Me, NT 4.0, 2000
	  var strBrwsr= navigator.userAgent.toLowerCase();
	  if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0){
	    if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6){
	      return false;
	    }
	    if(strBrwsr.indexOf("win98") > -1 ||
	       strBrwsr.indexOf("win 9x 4.90") > -1 ||
	       strBrwsr.indexOf("winnt4.0") > -1 ||
	       strBrwsr.indexOf("windows nt 5.0") > -1)
	    {
	      return false;
	    }
	    return true;
	  }else{
	    return false;
	  }
	}
	/**
	 * End of Click to activate IE fix code
	 */
