/**
 * JS for www.dylanamsterdam.com
 *
 * @project Dylanamsterdam
 * @author Vailshali,Manju.
 * @version 1.0
 * @copyright Copyright (c) 2011, W3 INDUSTRIES NV (http://www.w3industries.com)
 * @file script
 */

/**
 *  Changes History:
 * ===============
 *
 * Author				Modifed On		BugId/Description
 * -----------------------------------------------------------------------------------------
 * Vailshali                           12/03/2010		Initial Development
 * M K Nisar Uddin,Ramesh Teegapur     12/11/2011               Code Optimization and proper indentation
 */

    jQuery.noConflict();

	var pageUrl = window.location.href;
    //All Variables required for gallery JS are declared here

    // images path prefix
    var w3path =    '../';

    // div id tp close
    var current =   "div_0";

    leftHack = 0; // left padding if necessary

    topHack = 0;

    var bigImgHeights = 0;

    block_width =   160;

    var small_img = null;

    var spacer_block;

    spacer_block =  '<div class="spacer" ></div><div class="spacer" ></div>';

    var diff=0;

    //Variable declared for FAQ effect
    var gbl_click_var = 0;

    /* Lava Lamp code */
    var new_current = 0;

//Document ready function
 jQuery(function(){
 	
 	//Appending the FB like and share button on load to DOM
	//appendFacebookLike();
 	
 	//Load header images via AJAX
 	loadHeaderImages();
 	
    var bodyid = jQuery('body').attr('id');

    bodyid_new = bodyid.search("hotel");
    if (bodyid_new != -1) {
        new_current = (jQuery('#lavalamp').find('#' + "1"));
    }

    bodyid_new = bodyid.search("room");
    if (bodyid_new != -1) {
        new_current = (jQuery('#lavalamp').find('#' + "2"));
    }

    bodyid_new = bodyid.search("people");
    if (bodyid_new != -1) {
        new_current = (jQuery('#lavalamp').find('#' + "2"));
    }


    //Initializing the lavalamp PLUGIN
    /*jQuery('#lavalamp').lavaLamp( {
        fx :'backout',
        setOnClick :true
    });*/




    //Adjusting Padding of right widget
    if(jQuery("#widget_right_content").children().hasClass("articles_content") == true){
        jQuery("#widget_right_content").css({"padding-bottom":180+"px"});
    }
    else{
        jQuery("#widget_right_content").css({"padding-bottom":17+"px"});
    }

    /**
     * This is where all the necesaary function are called on page load
     */


    //To Make columns on page load
    call_columnize();

    //To clear current link menus from nav Categories menu
    clearCurrentLinkmenu();

	/**
	  * Binding click event for read more on landing page
	  */
	 jQuery(".read_more").bind('click',function(){
	  jQuery(this).parent().children(".short_desc").css('display','none');
	  jQuery(this).parent().children(".full_desc").css('display','block');
	  jQuery(this).css('display','none');
	  //Arranging the layout heights
	  reArrangeDynamicLayoutHeight();
	 });


    //Scrolling to top OnClick of Top button on FAQ page
    jQuery(".gototop_content").find('a').bind('click',function(){
        jQuery('body').scrollTo( {top:'0px', left:'0px'}, 800 );
    });


   /**
    *This Code is for slide Down effect when FAQ question is clicked
    */
    jQuery(".faq_q").bind('click',function() {
       //getting span id in the faq div
        var span_id = jQuery(this).find("span").attr("id");

        // checking that same faq is not clicked twice
        if(span_id!=gbl_click_var)
        {
            jQuery(".faq_a").slideUp("slow");
            jQuery(".faq_q").find('span').css({'display' :'block'});

            // assigning span id t0 the global variable , so that we can check if same faq clicked twice
            gbl_click_var = span_id;

            jQuery("#ans_" + span_id).slideDown("slow",
            function setArrowVisibility() {
                jQuery(".bottom_arrow").css( {"display" :"block"});

                /* FAQ dynamic height arrangement*/
                reArrangeDynamicLayoutHeight();
            });

            jQuery("#"+span_id).css({'display':'none'});
        }
        else // if same faq clicked twice
        {
            // closing that div
            jQuery(".faq_a").slideUp("slow",function()
            {
            //reArrangeDynamicLayoutHeight();
            });

            jQuery(".faq_q").find('span').css({'display' :'block'});

            // assigning 0 to global variable
            gbl_click_var = 0;
        }

    });//.faq_q Click event ENDS here



   /**
    *This Code is for slide UP effect when FAQ answer is clicked
    */
    jQuery(".bottom_arrow").bind('click', function() {
        jQuery(".faq_a").slideUp("slow");
        jQuery(".bottom_arrow").css({"display" :"none"});
        jQuery(".top_arrow").css({"display" :"block"});
        // when faq closing happend assigning 0 to the global variable
        gbl_click_var = 0;
    });


  //Inializing the datepicker plugin for Arrival date
      jQuery("#StartDateString").datepicker( {
          dateFormat :'D d M yy',
          minDate: +0 
      });
  
  	//Setting the default date as tudays date
  	jQuery("#StartDateString").datepicker('setDate', new Date());

    //To submit the BOOK ONLINE FORM
    jQuery("#bookonline_submit").bind('click',function(){
        var calArrivalDateField = jQuery('#bookonline_arrivaldate').val();
        var calDepartureDateField = jQuery('#bookonline_departuredate').val();
        var adultPersons = jQuery('#room_occupancy').val();
        var FormRedirect = document.forms['form_book'];
        FormRedirect.action = 'https://www.yourreservation.net/ibe/HUAMSBL/main.html?calArrivalDateField='+calArrivalDateField+'&calDepartureDateField='+calDepartureDateField+'&adults1='+adultPersons+'&childrenAges1=-1&quick=page1';
        FormRedirect.target = "_blank";
        FormRedirect.submit();
    });


    /**
     *Code for Gallery images starts here
     *
     */

    

    // checking and getting the number after # if page opens from tell a  friend link(from mail)
    var img_numbr = getFile(window.location.href);

    if(img_numbr>0)
    {
        var box_id = "div_"+img_numbr;

        if(jQuery("#"+box_id).length==1)
        {
            // new click block id to current
            current = box_id;

            // Open the Big Block, hide the small block
            openGalleryDetails(current,img_numbr);
        }
    }
    
    //Binding click event to thubnail to show big images
    jQuery(".block").bind('click',function(){

        var gallery_content = jQuery('#gallery_content');
        // assign to previous  ( old )
        old = current;

        // Close the Previous block
        if (getDivId(old,1)!="0" ){
            closeBlock(old);
        }

        // new click block id to current
        current = this.id;

        // Open the Big Block, hide the small block
        var ImgClicked = current.substring(4);
       
        
        //If its image gallery page 
        if(jQuery('.ajax_get_detials').length == 0){
        		var img_details_url = jQuery(this).find('.ajax_read_more').val();
	            // Calling AJAX function to fetch image details based on channel entry_id
	            jQuery.ajax({
	                    url : img_details_url,
	                    async : false,
	                    success : function(response){
	                    // make the response jQuery-able and strore in var
	                    var img_details_el = jQuery(response);
	
	                    //removing the previous img-details div from DOM
	                    gallery_content.find('.gallery_big').css('display','none').remove();
	
	                    // appending the response to gallery container
	                    gallery_content.append(img_details_el);
	                    
	                    //changing the URL of thge page based on the gallery details
	                    var galleryTitle = jQuery('.gallery_big').find('h3').html();
	                    
	                    //Changing the URL of the page as per Thumnail clicked
	                    parent.location.hash = '#'+ImgClicked;
	                    
	                    jQuery('#bdiv_').attr('id','bdiv_'+ImgClicked);
	                    jQuery('#img_').attr('id','img_'+ImgClicked);
	
	                    //Binding the close click event to the newly append Div in DOM
	                    jQuery(".close_button").bind('click',function(){
	                        //getting the ID of the block clicked for closing
	                        var id = jQuery(this).parent().attr('id');
	                        var strLength = id.length;
	                         id     = id.substring(1,strLength);
	
	                        //Closing the clicked block
	                        closeBlock(id);
	                        current = "div_0";
	                        setGalleryDivHeight('close');
	                    });
						
						//Bind the click event to tell a friend
						bindTellaFriendClick();
						
	                    // Open the Big Block, hide the small block
	                       openBlock(current);
	                    }
	            });
            }else{
            	 var img_details_url = jQuery(this).find('.ajax_get_detials').val();
            	 // Calling AJAX function to fetch image details based on channel entry_id
	             jQuery.ajax({
	                     url : img_details_url,
	                     async : false,
	                     success : function(response){
	                     // make the response jQuery-able and strore in var
	                     var img_details_el = jQuery(response);
	 
	                     //removing the previous img-details div from DOM
	                     gallery_content.find('.gallery_big').css('display','none').remove();
	 
	                     // appending the response to gallery container
	                     gallery_content.append(img_details_el);
	                     
	                     //changing the URL of thge page based on the gallery details
	                    var galleryTitle = jQuery('.gallery_big').find('h3').html();
	                    
	                    //Changing the URL of the page as per Thumnail clicked
	                    parent.location.hash = '#'+ImgClicked;

	                     jQuery('#bdiv_').attr('id','bdiv_'+ImgClicked);
	                     jQuery('#img_').attr('id','img_'+ImgClicked);
	 
	                     //Binding the close click event to the newly append Div in DOM
	                     jQuery(".close_button").bind('click',function(){
	                         //getting the ID of the block clicked for closing
	                         var id = jQuery(this).parent().attr('id');
	                         var strLength = id.length;
	                         id     = id.substring(1,strLength);
	 
	                         //Closing the clicked block
	                         closeBlock(id);
	                         current = "div_0";
	                         setGalleryDivHeight('close');
	                     });
	 					 //Bind the click event to tell a friend
							bindTellaFriendClick();
							
	                     // Open the Big Block, hide the small block
	                        openBlock(current);
	                     }
	             });
            }
    });


    

    /***Code for Gallery images ENDS here***/
   

   


    /**
     *Form Validations are done here
     */

    //Contact page form Validation
    jQuery("#submitContact").bind('click',function(){
        var contactEmail=jQuery("#Emailaddress").val();
        var contactLName=jQuery("#Lastname").val();
        var contactPhone=jQuery("#Phonenumber").val();
        var strQuestion = jQuery('#Question').val();
        var error_color = "#FF0000";
        var no_error    = "#404041";
        var regEmail=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        var regPhone =/^((\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$)/i;
        var errors="";
		
		
        //Email Validation
        if(contactEmail=="" || contactEmail==null){
            jQuery("#Emailaddress").css("background",error_color);
            errors+="<span>"+"Please enter Email address"+"</span>";
        }
        else if(!regEmail.test(contactEmail)){
            jQuery("#Emailaddress").val("Please Enter the valid e-mail address")
                                   .css({background:error_color,color:"black"});
            errors+="<span>"+"Please enter a valid Email address"+"</span>";
        }else{
            jQuery("#Emailaddress").css({"background":no_error,color:"#ffffff"});
        }

        //LastName Validation
        if(contactLName=="" || contactLName==null){
            jQuery("#Lastname").css("background",error_color);
            errors+="<span>"+"Please enter Last name."+"</span>";
        }else{
            jQuery("#Lastname").css("background",no_error);
        }
		
		//Gender Validation 
		if(!jQuery('#Gender_m').attr('checked') && !jQuery('#Gender_f').attr('checked')){
			errors+="<span>"+"Please select Gender."+"</span>";
		
		}
		
		
		//Country Validation
		if(jQuery('select#Country option:selected').val() === 'SelectedIndex'){
			errors+="<span>"+"Please select Country."+"</span>";
		}
		
		//Language Validation Validation 		
		if(!jQuery('#Language_1').attr('checked') && !jQuery('#Language_2').attr('checked')){
			errors+="<span>"+"Please select Language."+"</span>";
		
		}
		
		//Question Validation
		if(strQuestion=="" || strQuestion==null){
		    jQuery("#Question").css("background",error_color);
		    errors+="<span>"+"Please enter Question."+"</span>";
		}else{
		    jQuery("#Question").css("background",no_error);
		}
		
        //Phone Number Validation
        if(contactPhone=="" || contactPhone==null){
            jQuery("#Phonenumber").css("background",error_color);
            errors+="<span>"+"Please enter Phone number "+"</span>";
        }
        else if(!regPhone.test(contactPhone)){
            jQuery("#Phonenumber").css({background:error_color,color:"black"})
                                  .val("Please Enter the numbers only");
            errors+="<span>"+"Please enter a valid phone number."+"</span>";
        }else{
            jQuery("#Phonenumber").css({"background":no_error,color:"#ffffff"});
        }
		
        //If there are no errors
        if(errors!=""){
        	
            jQuery("#main_inner").css('height','1240');
            jQuery(".error_consolidated").css('display','block');
            jQuery(".error_consolidated_middle").find('.errorbox')
                                                .html('')
                                                .append(errors);
            
        return false;
        }
        else if(errors==""){
            return true;
        }
    });// End of contact form validation script //

    //Empty the email adress input box on click
    jQuery("#Emailaddress").bind('click',function(){
        jQuery("#Emailaddress").val("");
    });

    //Empty the phone number input box on click
    jQuery("#Phonenumber").bind('click',function(){
        jQuery("#Phonenumber").val("");
    });


    //Validation of keep me posted Form
    jQuery("#submitContactKeep").bind('click',function(){
            var contactEmail=jQuery("#Emailaddress").val();
            var contactLName=jQuery("#Lastname").val();
            var contactGender=jQuery('input:radio[name=Gender]:checked').val() != undefined;
            var contactLanguage=jQuery('input:radio[name=Language]:checked').val() != undefined;
            var contactCountry=jQuery("#Country option:selected").val();
            var error_color = "#FF0000";
            var no_error_color = "#404041";
            var regEmail=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            var errors="";

            //Email validation
            if(contactEmail=="" || contactEmail==null){
                errors+="- Geen waarde ingevuld voor Email address.\n";
            }
            else if(!regEmail.test(contactEmail)){
                errors+="- Ongeldig waarde ingevuld voor Email address.\n";
            }


            //Last Name Validation
            if(contactLName=="" || contactLName==null){
                errors+="- Geen waarde ingevuld voor Last name.\n";
            }
			
			
            //Gender Validation
            if(contactGender==false){
                errors +="- Geen keuze gemaakt voor Gender.\n";
            }
			
            //Country Validation
            if(contactCountry=='null'){
                errors+="- Geen waarde ingevuld voor Country.\n";
            }


            //Language Vlaidation
            if(contactLanguage==false){
                errors +="- Geen keuze gemaakt voor Language.\n";
            }

            //If errors exists alert to the User
            if(errors!=""){
                alert('Het formulier kon niet worden verzonden om de volgende reden(en):\n\n'+errors);
                return false;
            }
            else if(errors==""){
                return true;
            }
    });
    
    //prettyphoto intialization
		jQuery("a[rel^='prettyPhoto']").prettyPhoto();
	
	//If theres only one image in the article galery removing the NEXT-PREV buttons
	jQuery('.gallery_slideshow').each(function(){
		if(jQuery(this).find('a').size()== 1){
			jQuery(this).find('a').attr('rel','prettyPhoto'); 
		}
	});
	
	// Remove last border for articles
	jQuery('.articles:last').addClass('last');
	
	
	
	/**
	 *When FAQ question is clicked clicked showing answer in slideDown effect
	 */
	
	var gbl_click_var = 0;
		// Code for slide down when FAQ question is clicked
		jQuery(".faq").click(function() {
		
			//getting span id in the faq div
			var span_id = jQuery(this).find("span").attr("id");
		
			// checking that same faq is not clicked twice
			if(span_id != gbl_click_var) {
				jQuery(".fga").slideUp("slow");
				jQuery(".faq").find('span').css({
					'display' : 'block'
				});
		
				// assigning span id t0 the global variable , so that we can check if same faq clicked twice
				gbl_click_var = span_id;
		
				jQuery("#ans_" + span_id).slideDown("slow", function setArrowVisibility() {
					jQuery(".bottom_arrow").css({
						"display" : "block"
					});
		
					/* FAQ dynamic height arrangement*/
					reArrangeDynamicLayoutHeight();
				});
		
				jQuery("#" + span_id).css({
					'display' : 'none'
				});
			} else// if same faq clicked twice
			{
		
				// closing that div
				jQuery(".fga").slideUp("slow", function() {
		
				});
		
				jQuery(".faq").find('span').css({
					'display' : 'block'
				});
		
				// assigning 0 to global variable
				gbl_click_var = 0;
			}
		
		});//jQuery(".faq").click() ends here
		// Code for slide Up when FAQ answer is clicked
		jQuery(".bottom_arrow").click(function() {
			jQuery(".fga").slideUp("slow", function() {
		
			});
		
			jQuery(".bottom_arrow").css({
				"display" : "none"
			});
			jQuery(".top_arrow").css({
				"display" : "block"
			});
			// when faq closing happend assigning 0 to the global variable
			gbl_click_var = 0;
		});//jQuery(".bottom_arrow").click() ends here
			

	
 });//Document ready function ENDS here



 /**
  * All functions are declared here
  *
  */
 
 	/*This function appends the facebook like and share button code to the DOM
 	 var appendFacebookLike = function (){
 		 var StrFbLike = '<div class="fb_like_container" style="float:left;margin-bottom:40px; border-bottom:1px dotted #898788;padding-bottom:10px;"><span style="padding-bottom:10px;float:left;">Like this and share it with friends Now!</span><div class="fb-like" data-href="'+pageUrl+'" data-send="true" data-layout="button_count" data-width="220" data-show-faces="false"></div></div>';
		 jQuery("#keepmepost").prepend(StrFbLike);
 	 }*/
 	
 	
 	//Loading hedaer image per page via AJAX
 	var loadHeaderImages = function(){
		if(pageUrl.indexOf('#')!= -1){
			var mainUrl = pageUrl.split("#");
			//console.log(mainUrl);
			var arrUrlSplit = mainUrl[0].split("/");	
			var pageTitleUrl = arrUrlSplit[arrUrlSplit.length-2];
			
		} else {		
			var pageTitleUrl = jQuery("#page-uri").val();
		}
		//Checking if the page is image gallery view
		if(pageUrl.indexOf('view/c')=== -1){
			jQuery.ajax({
	                url : '../../includes/header-image/'+pageTitleUrl,
	                success : function(response){
	                	//alert(response);
		                // make the response jQuery-able and strore in var
		                var img_details_el = jQuery(response);
		                //If browser is IE& then fadingOut and fadeIn the header image as a hack
		                if(jQuery('.ie7').length > 0){
					    	jQuery("#header_image").prepend(img_details_el).fadeOut().fadeIn();
					    }else{
					    	jQuery("#header_image").prepend(img_details_el);
					    }	
	                }
		   });
	   } else {
	   		jQuery.ajax({
	   		         url : '../../../includes/header-image/'+pageTitleUrl,
	   		         success : function(response){
	   		         	//alert(response);
	   		             // make the response jQuery-able and strore in var
	   		             var img_details_el = jQuery(response);
	   		             //If browser is IE& then fadingOut and fadeIn the header image as a hack
	   		             if(jQuery('.ie7').length > 0){
	   					    	jQuery("#header_image").prepend(img_details_el).fadeOut().fadeIn();
	   					    }else{
	   					    	jQuery("#header_image").prepend(img_details_el);
	   					    }	
	   		         }
	   		});
	   }
 	}
 	
 	
 	
 	
 	
 	
 	
 	
	//This function opens the gallery details based on the param 
	//usually the request comes from other sites like from facebook
	//when the page is shared
	var openGalleryDetails = function(thisObj,img_numbr)
	{
	
		//getting an idea about the row number in which the gallery exists on page
		var row = img_numbr/4;
		
		var gallery_content = jQuery('#gallery_content');
        // assign to previous  ( old )
        old = current;

        // Close the Previous block
        if (getDivId(old,1)!="0" ){
            closeBlock(old);
        }

        // new click block id to current
        current = thisObj;

        // Open the Big Block, hide the small block
        var ImgClicked = current.substring(4);
       
        
        //If its image gallery page 
        if(jQuery('.ajax_get_detials').length == 0){
        		var img_details_url = jQuery("#"+thisObj).find('.ajax_read_more').val();
	            // Calling AJAX function to fetch image details based on channel entry_id
	            jQuery.ajax({
	                    url : img_details_url,
	                    success : function(response){
	                    // make the response jQuery-able and strore in var
	                    var img_details_el = jQuery(response);
	
	                    //removing the previous img-details div from DOM
	                    gallery_content.find('.gallery_big').css('display','none').remove();
						
	                    // appending the response to gallery container
	                    gallery_content.append(img_details_el);
	                    
	                    jQuery('#bdiv_').attr('id','bdiv_'+ImgClicked);
	                    jQuery('#img_').attr('id','img_'+ImgClicked);
	
	                    //Binding the close click event to the newly append Div in DOM
	                    jQuery(".close_button").bind('click',function(){
	                        //getting the ID of the block clicked for closing
	                        var id = jQuery(this).parent().attr('id');
	                        var strLength = id.length;
	                         id  = id.substring(1,strLength);
	
	                        //Closing the clicked block
	                        closeBlock(id);
	                        current = "div_0";
	                        setGalleryDivHeight('close');
	                    });
						//Bind the click event to tell a friend
							bindTellaFriendClick();
	                    // Open the Big Block, hide the small block
	                       openBlock(current);
	                    }
	            });
            }else{
            	 var img_details_url = jQuery("#"+thisObj).find('.ajax_get_detials').val();
            	 // Calling AJAX function to fetch image details based on channel entry_id
	             jQuery.ajax({
	                     url : img_details_url,
	                     success : function(response){
	                     // make the response jQuery-able and strore in var
	                     var img_details_el = jQuery(response);
	 
	                     //removing the previous img-details div from DOM
	                     gallery_content.find('.gallery_big').css('display','none').remove();
	 
	                     // appending the response to gallery container
	                     gallery_content.append(img_details_el);
	                 
	                     jQuery('#bdiv_').attr('id','bdiv_'+ImgClicked);
	                     jQuery('#img_').attr('id','img_'+ImgClicked);
	 
	                     //Binding the close click event to the newly append Div in DOM
	                     jQuery(".close_button").bind('click',function(){
	                         //getting the ID of the block clicked for closing
	                         var id = jQuery(this).parent().attr('id');
	                         var strLength = id.length;
	                         id  = id.substring(1,strLength);
	 
	                         //Closing the clicked block
	                         closeBlock(id);
	                         current = "div_0";
	                         setGalleryDivHeight('close');
	                     });
	 					//Bind the click event to tell a friend
							bindTellaFriendClick();
	                     // Open the Big Block, hide the small block
	                        openBlock(current);
	                     }
	             });
            }
            
            //Scrolling page down based on the gallery to be opened
            if(row <= 1){
            	jQuery('body').scrollTo( {top:'420px', left:'0px'}, 2000 );	
            } else if (row > 1 && row <= 2){
            	jQuery('body').scrollTo( {top:'653px', left:'0px'}, 2000 );	
            } else if (row > 2 && row <= 3){
            	jQuery('body').scrollTo( {top:'886px', left:'0px'}, 3000 );	
            } else if (row > 3 && row <= 4){
            	jQuery('body').scrollTo( {top:'1119px', left:'0px'}, 3000 );	
            } else if (row > 4 && row <= 5){
            	jQuery('body').scrollTo( {top:'1352px', left:'0px'}, 3000 );	
            } else if (row > 5 && row <= 6){
            	jQuery('body').scrollTo( {top:'1585px', left:'0px'}, 3000 );	
            } else if (row > 6 && row <= 7){
            	jQuery('body').scrollTo( {top:'1818px', left:'0px'}, 3000 );	
            } else if (row > 7 && row <= 8){
            	jQuery('body').scrollTo( {top:'2051px', left:'0px'}, 3000 );	
            } 
            
	}//openGalleryDetails function ends here
	
	

    // To make columns
    var call_columnize = function ()
    {
        var $left_content = jQuery('#left_content');
        if($left_content.length > 0) {
            var content = $left_content.html();
            var content1 = jQuery.trim(content);

            if(content1 != ''){

                if(!$left_content.hasClass("dontsplit")){

                    var curCol=0;
                    //find out if any <hr> tags in the content, if not found call jquery columnize, otherwise call custom columnizer to split at <hr> tag
                    var hr_tags=document.getElementsByTagName("hr");
                    if(hr_tags.length<1) {

                        $left_content.columnize(
                        {
                            width:220,
                            lastNeverTallest:true,
                            doneFunc: function()
                            {
                                arrangeDynamicLayoutHeight();
                                curCol++;
                            }
                        });
                    }//4th if ends here
                    else{
                        $left_content.makeColumns(
                        {
                            width:220,
                            doneFunc: function()
                            {
                                arrangeDynamicLayoutHeight();
                            }
                        });
                    }//4th else ends here
                }//3rd if ends
                else {
                    arrangeDynamicLayoutHeight();
                }
            }//2nd if ends
            else{
                arrangeDynamicLayoutHeight();
            }
        }//1st If ends
        else{
            arrangeDynamicLayoutHeight();
        }
    }//Function call_columnize ENDS


    //To store related topics height
    var arrangeDynamicLayoutHeight = function(){
        var $left = jQuery('#left');
        var $container = jQuery("#container");
        //right side bottom content height
        var rightBottomContentHeight = 0;
        rightBottomContentHeight = jQuery('.topics').height();

        //left side bottom content height
        var leftBottomContentHeight = 0;
        leftBottomContentHeight = jQuery('.bottom_left').height();

        //middle bottom content height
        var middleBottomContentHeight = 0;
        middleBottomContentHeight = jQuery('.seperator').height();

        //clearfooter height
        var clearFooterHeight = jQuery('.clearfooter').height();

        //set left clearfooter height
        $left.children('.clearfooter')
                       .css({'height':(leftBottomContentHeight+clearFooterHeight)+'px'});

        //set middle clearfooter height
        var resetBottomClearfooterHeight = Math.max(rightBottomContentHeight,middleBottomContentHeight);
        $container.children('.clearfooter')
                            .css({'height':(resetBottomClearfooterHeight+clearFooterHeight)+'px'});

        //window height
        var windowHeight = jQuery(window).height();

        //left container height
        var leftContentHeight = $left.height();

        //middle container height
        var middleContentHeight = $container.height();

        var resultHeight = Math.max(leftContentHeight,middleContentHeight,windowHeight);

        $left.css({'height':resultHeight+'px'});

        $container.css({'height':resultHeight+'px'});

        jQuery("#main_inner").css({'height':resultHeight+'px'});

    }//function arrangeDynamicLayoutHeight



    //To re arrange Dynamic Layout Height
    var reArrangeDynamicLayoutHeight = function ()
    {
        var left = jQuery('#left');
        var container = jQuery('#container');
        var main_inner = jQuery('#main_inner');

        left.css({'height':'auto'});
        container.css({'height':'auto'});
        main_inner.css({'height':'auto'});

        //window height
        var windowHeight = jQuery(window).height();

        //left container height
        var leftContentHeight = left.height();

        //middle container height
        var middleContentHeight = container.height();

        var resultHeight = Math.max(leftContentHeight,middleContentHeight,windowHeight);

        left.css({'height':resultHeight+'px'});
        container.css({'height':resultHeight+'px'});
        main_inner.css({'height':resultHeight+'px'});
    }




     /* with no arguments you get back the number after # of the page that is currently loaded on the browser */
    var getFile = function (str)
    {
        if("undefined"  ==  typeof(str))
            str=location.href;
        str = str.split(/[\#\\]/);

        var ck_number = /^[0-9]{1,5}$/;

        if ( ck_number.test(str[str.length-1]) )
            return (str[str.length-1]);
        else
            return '0';
    }


    //Open the Clicked block
    var openBlock = function (thisId)
    {
        var k = 0;
        jQuery(".spacer").remove();

        var id = thisId;

        var offset = jQuery("#"+id).position();

        // current clicked block dimensions
        ob_x = offset.left;
        ob_y = offset.top;

        // current big div dimensions to after opening
        ob_w = jQuery("#b"+id).outerWidth(true);
        ob_h = (jQuery("#b"+id).outerHeight(true)) + bigImgHeights;

        // get the height of the open block
        rows = Math.ceil(((ob_h)/234));

        big_div_id = getDivId(id,1);

        // for intersecting rows, insert the spacer divs
        for(i=0; i<rows; i++)
        {
           if(k==0){
                if(big_div_id == 1){
                    jQuery("#div_"+(big_div_id)).after(spacer_block)
                    jQuery("#b"+id).fadeIn('medium')
                                   .css({ 'display':'block',   'position':'absolute', 'left':(ob_x + leftHack)+'px', 'top':(ob_y + topHack)+'px'});
                }
                else if(big_div_id%4==0) { // this is for last column of any row
                    jQuery("#div_"+(big_div_id-2+k)).after(spacer_block);
                    jQuery("#b"+id).fadeIn('medium')
                                   .css({'display':'block',   'position':'absolute', 'left':(ob_x + leftHack - block_width -20 )+'px', 'top':(ob_y + topHack)+'px'});
                }
                else{
                    jQuery("#div_"+(big_div_id-1+k)).after(spacer_block);
                    jQuery("#b"+id).fadeIn('medium')
                                   .css({ 'display':'block',   'position':'absolute', 'left':(ob_x + leftHack)+'px', 'top':(ob_y + topHack)+'px'});
                }
            } //1st If ends here
            else if(big_div_id%4==0){
                jQuery("#div_"+(big_div_id-1+k)).after(spacer_block);
            }
            else{
                jQuery("#div_"+(big_div_id-1+k+1)).after(spacer_block);
            }

            k+=2;
        }//For loop ends here

        //Making Big image div hidden
        jQuery("#div_"+big_div_id).css("display","none");

        //for adjusting the height on click of the small image
        setGalleryDivHeight(id);

    }//Function openBlock Ends here

	//bindind the click event to tell afriend form  
	var bindTellaFriendClick = function()
	{
		var ck_username = /^[A-Za-z0-9_ ]{3,20}$/;
	    var err_color = "#FF0000";
	    jQuery(".tell_a_friend_submit").bind('click',function () {
	
	        var val_count = 2;
	
	        var gallery_id = jQuery(this).prev().val();
	
	        var form_name = jQuery("#galleryName_"+gallery_id);
	        var form_email = jQuery("#galleryEmail_"+gallery_id);
	
	        var form_name_value = form_name.val();
	        var form_email_value = form_email.val();
	
	        var form_name_check = form_name_value.replace(/^\s+|\s+$/g, '') ;
	        var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
	
	        if(form_name_check=='' || !ck_username.test(form_name_value)){
	            val_count--;
	            form_name.css({"background":err_color});
	        }
	        else{
	            form_name.css({"background":"#808184"});
	        }
	
	        if(!form_email_value.toUpperCase().match(regEmail)){
	            val_count--;
	            form_email.css({"background":err_color});
	        }
	        else{
	            form_email.css({"background":"#808184"});
	        }
	
	        var pageUrlOnClick = window.location.href;
	        
	        FRNDLY_URL = "tell_a_friend.php";
	        if(val_count==2){
	            jQuery.ajax({
	                type: "POST",
	                url:'/includes/ajax/'+FRNDLY_URL,
	                data: "name="+form_name_value+"&email="+form_email_value+"&pageUrlOnClick="+pageUrlOnClick+"&form_type=T_A_F&IsAjax=true",
	                success: function(msg){
	                    if(msg==1){
	                        jQuery("#tell_a_friend"+gallery_id)[0].reset();
	                        form_email.css({"background":""});
	                        jQuery("#tellafriend_successmsgbox_"+gallery_id).html("Successfully sent");
	                        jQuery("#tellafriend_errmsgbox_"+gallery_id).css({"display":"none"});
	                        jQuery("#tellafriend_successmsgbox_"+gallery_id).css({"display":"block"});
	                    }
	                    else{
	                        form_email.css({"background":err_color});
	                        jQuery("#tellafriend_errmsgbox_"+gallery_id).html("Some problem with email ID");
	                        jQuery("#tellafriend_successmsgbox_"+gallery_id).css({"display":"none"});
	                        jQuery("#tellafriend_errmsgbox_"+gallery_id).css({"display":"block"});
	                    }
	                },
	                error: function(msg)
	                {
	                    alert("Unable to get the result");
	                }
	            });
	
	        }
	
	    });
	
	  /***tell_a_friend_submit click event ends here***/
	}
	
    //for adjusting the height on click of the small image  - manju
    var setGalleryDivHeight = function (divId)
    {
        if(divId != 'close'){
            var gallery_content = jQuery("#gallery_content");
            var main_inner = jQuery("#main_inner");
            var gallery_item_height = jQuery("#b"+divId).height();

            var offset = jQuery("#b"+divId).offset();

            var offset_top = offset.top;

            var gallery_height = gallery_content.height();

            var gallery_offset = gallery_content.offset();

            if(gallery_item_height+offset_top < gallery_height+gallery_offset.top)
            {
                page_height = offset_top + gallery_height;

                gallery_item_heightv = gallery_item_height+offset_top;

                var gallery_heightv = gallery_height+offset_top;

                page_height -=43;
            }//2nd If close
            else
            {
                page_height = offset_top + gallery_item_height
            }

            page_height +=182;

            var compareHeight = main_inner.height();
            var resultPageHeight = Math.max(compareHeight,page_height);
            jQuery("#container").height(resultPageHeight);
            jQuery("#left").height(resultPageHeight);
            main_inner.height(resultPageHeight);
        }//1st if closes here

    }//function setGalleryDivHeight ends here


    //To close the opened block
    var closeBlock = function (id)
    {
        //Hiding the big image
        jQuery("#b" + id).css("display","none");
        //Showing the small image
        jQuery("#" + id).css("display","block");

        jQuery(".spacer").remove();

        //Arranging the layout heights
        reArrangeDynamicLayoutHeight();
    }

    // Return the id number, (div_1 = returns 1)
    var getDivId = function (stringId,index)
    {
        var ids = stringId.split("_");
        return ids[index];
    }


    //Function to add selected class to Nav categories menu
    var clearCurrentLinkmenu =function (){
        if(document.getElementById("nav_categories"))
        {
            var a = document.getElementById("nav_categories").getElementsByTagName("A");
            for(var i=0;i<a.length;i++){
                if(a[i].href == window.location.href.split("#")[0])
                    addNode1(a[i]);
            }
        }
    }

    var addNode1 = function (n){
        n.parentNode.className="selected";
    }
