    
    var offersPerPage = 10;
    
    var lastPage = 0;
    var currentPage = 0;
    var divBrandOffers = null;
    var number_of_items = 0;
    var navigation_html = "";
    var language = "";
    var text_All = "";
    
    $(document).ready(function(){    	
		setLanguage();
		setPagePagination();
    });
 
 	function setLanguage(){
     	for(i=0;i<$("ul#language").children().size();i++)
    	{
    		if($("ul#language").children().children().eq(i).hasClass("selected")){
    			language = $("ul#language").children().children().eq(i).text();
    			break;	
    		}
    	}

		switch(language)
		{
			case "fr": text_All = "Toutes";
				break;
			case "es": text_All = "Todas";
				break;
			case "ca": text_All = "Totes";
				break;
			case "de": text_All = "Alle";
				break;
			case "nl": text_All = "Alle";
				break;
			case "it": text_All = "Tutti";
				break;
			case "zh": text_All = "查看所有";
				break;
			case "pt-br": text_All = "Ver todos";
				break;
			case "ru": text_All = "Просмотреть все";
				break;
			default: text_All = "View all";
		}
 	}
 
 	function setPagePagination(){
 		// clean out the container before adding new content
 		$('#page_navigation').empty();
 		
 		divBrandOffers = $('div.brandOffers');
        
        //getting the amount of elements inside Brand Offers div  
        number_of_items = divBrandOffers.children().size();  

        //calculate the number of pages we are going to have  
	    var number_of_pages = Math.ceil(number_of_items/offersPerPage);

        if(number_of_pages > 1){
         
         	// calculate height of offers container
         	var height = 133*Math.round(offersPerPage / 2);

         	$('div.brandOffers:not(#hotelsBooking)').css("height",height);
         
	        lastPage = number_of_pages-1;
	
	        /* 
	        what are we going to have in the navigation? 
	            - link to previous page 
	            - links to specific pages 
	            - link to next page 
	        */  
	        navigation_html = '<a id="previous" style="font-size:18px;" class="previous_link" href="javascript:previous();"> </a>';  
	        
	        var current_link = 0;  
	        
	        while(number_of_pages > current_link){ 
	        	var pageId = "Page" + current_link;
	            navigation_html += '<a id="'+pageId+'" class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">&nbsp; '+ (current_link + 1) +' &nbsp;</a>';  
	            current_link++; 
	        }
	        
	        navigation_html += '<a id="next" style="font-size:18px;" class="next_link" href="javascript:next();"> </a>';
	        navigation_html += '<a id="show-all" class="show_all" href="javascript:showAll();">' + text_All + '</a>'; 
	        
	        $('#page_navigation').html(navigation_html);  
	      
	        //add active_page class to the first page link  
	        $('#page_navigation .page_link:first').addClass('active_page');  
	      
	        //hide all the elements inside Brand Offers div  
	        divBrandOffers.children().css('display', 'none');  
	      
	        //and show the first n (show_per_page) elements  
	        divBrandOffers.children().slice(0, offersPerPage).css('display', 'block');
	        $('#Page'+0).css('font-weight', 'normal'); 
	    }
 	}
 
 	function showAll(){
 		// calculate the height required to show all offers on div
 		var height = 133*Math.round(number_of_items / 2);
 		
 		// show all offers
 		divBrandOffers.children().css('display', 'block');
 		
 		// ajust height of div to show all offers 
 		$('div.brandOffers').css("height",height);
 		
 		// clear container
 		$('#page_navigation').empty();
 		
 		// add option to revert back to page pagination
 		//navigation_html = '<a id="show-less" class="show_all" href="javascript:showLess();"> Less </a>';   
	    //$('#page_navigation').html(navigation_html); 
 	}

 	function showLess(){
 		pagePagination();
 	}

    function previous(){  
        new_page = currentPage - 1; 
         
        //if there is an item before the current active link run the function  
        if($('.active_page').prev('.page_link').length==true){  
            go_to_page(new_page);
        }
    }  
      
    function next(){   
        new_page = currentPage + 1;
        
        //if there is an item after the current active link run the function  
        if($('.active_page').next('.page_link').length==true){  
            go_to_page(new_page);  
        } 
    }  
    
    function go_to_page(page_num){
    	
        new_page = currentPage;
    	  
        //get the number of items shown per page  
        var show_per_page = parseInt(offersPerPage);
        
        //get the element number where to start the slice from  
        start_from = page_num * show_per_page;  
      
        //get the element number where to end the slice  
        end_on = start_from + show_per_page;  
        
        divBrandOffers.children().css('display', 'none').slice(start_from, end_on).fadeIn('slow');
      
        /*get the page link that has longdesc attribute of the current page and add active_page class to it 
        and remove that class from previously active page link*/  
        $('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');  
        
        // Highlight selected page
      	$('#Page'+currentPage).css('font-weight', 'lighter');
        $('#Page'+page_num).css('font-weight', 'normal');

        //update the current page input field  
        currentPage = page_num;
        
     /*   if(currentPage == 0){
        	$('#previous').css('visibility', 'visible');
        }else{
        	$('#previous').css('visibility', 'visible');
        }
        
        if(currentPage == lastPage){
        	$('#next').css('visibility', 'hidden');
        }else{
        	$('#next').css('visibility', 'visible');
        }*/
    }
