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');
});
	/**
	 * 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;
		
		// Looping through the all mtpl elements
//		for(v=0; v < allMtplArray.length; v++)
//		{
//			// getting the all mtpl elements of each one
//			var mtplArray = jQuery("body").find("."+allMtplArray[v]);
//			if(mtplArray.length > 0) {
//				
//				if(v != 0) {
//					groupMinJsStr += ","+ W3FE_BASE_URL +'/prototype/_includes/' + allMtplArray[v] + "/" + allMtplArray[v]+".js";
////					groupMinCssStr += ","+ W3FE_BASE_URL +'/prototype/_includes/'+ allMtplArray[v] + "/" + allMtplArray[v]+".css";
//				} else {
////					groupMinJsStr += W3FE_BASE_URL + '/prototype/_includes/'+ allMtplArray[v] + "/" + allMtplArray[v]+".js";
////					groupMinCssStr += W3FE_BASE_URL + '/prototype/_includes/' + allMtplArray[v] + "/" + allMtplArray[v]+".css";
//				}
//			}
//			
//		}
//		
//		// checking the mtpl element exists or not
//		if(groupMinCssStr != "") {
//			// Adding the corresponding css file dyanamically to head
//			jQuery("head").append('<link rel="stylesheet" type="text/css" href="'+W3FE_BASE_URL+'/min/f='+groupMinCssStr+'" />');
//		}
//		if(groupMinJsStr != "") {		
//			// adding the corresponding js file dyanamically to head
//			jQuery("head").append('<script type="text/javascript" src="'+W3FE_BASE_URL+'/min/f='+groupMinJsStr+'"></script>');
//		}
		
		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();
			jQuery(this).remove();
			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){
		var ieRandom = Math.round(Math.random()*999999);	
		url = url+"?random="+ieRandom		
		var targetWidth = jQuery(target).css('width');
		var targetHeight = jQuery(target).css('height');
		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);
				var imageWidth = jQuery(this).css('width');
				var imageHeight = jQuery(this).css('height');
				jQuery(this).attr("alt", "");
//				jQuery(this).attr("width", imageWidth);
//				jQuery(this).attr("height", imageHeight);
		}).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;
		}
	}
	
	/**
	 * Contact form JS for onfocus and onblur functionality
	 */
		jQuery(document).ready(function()
		{

//				jQuery(".input_text").focus(function()
//			jQuery(".jNiceInput").focus(function()
//				{
//					
//				jQuery(this).val('');
////					jQuery(this).parent().children("span").css("visibility","hidden");
//
//				});
//
//				jQuery(".jNiceInput").blur(function()
//				{				
//					if(jQuery(this).val() == jQuery(this).attr('title') || jQuery(this).val()=='')
//					jQuery(this).parent().children("span").css("visibility","visible");
//				});

			});
	
	/**
	 * 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'});
			}
		});
	});
	
