    // When document has loaded, initialize pagination and form 
    $(document).ready(function(){

			var currMemberId;

			        /**         * @param {int}page_index New Page index         * @param {jQuery} jq the container with the pagination links as a jQuery object         */
					function pageselectCallback(page_index, jq){

			            // Get number of elements per pagionation page from form
			            var items_per_page = 8;
			            var max_elem = Math.min((page_index+1) * items_per_page, members.length);
			            var newcontent = '';

			            // Iterate through a selection of the content and build an HTML string
			            for(var i=page_index*items_per_page;i<max_elem;i++)
			            {
			                newcontent += '<div class="entry">';
			                newcontent += '<a href="#' + members[i][3] + '" >';
			                newcontent += '<img src="' + members[i][1] + '" />';
							newcontent += '</a>';
							newcontent += '<h3>' + members[i][0] + '</h3>';
							newcontent += '</div>';
			            }

			            // Replace old content with new content
			            $('#Searchresult').html(newcontent);

						$('.entry a').click(function(){ 

						   if(($(this).attr('href').match(/#(\w.*)/) !== null)){
						       		currMemberId = $(this).attr('href').match(/#(\w.*)/)[1];
						   }else{
									currMemberId = 0;
						   }
						
						   $('.entry a.selectedThumb').removeClass("selectedThumb");	 
						   $(this).addClass("selectedThumb");						

							var newJSON_URL = "/project/vmanmodelsearch/json/entry/"+currMemberId;

							$.getJSON(newJSON_URL,
								
							        function(data){
									    
												$("#mainImg").attr('src', data.headshot.src);															
												$("#topEntryDetails h2").remove();													
												$("#imageLinks h3").remove();													
												$("#entryDetails p").remove();
												$("#entryDetails h2").remove();	
												$("#entryDetails h3").remove();	
												$("#entryDetails a").remove();	
												$("#entryDetails br").remove();	

												$("#topEntryDetails").append('<h2>'+data.details.firstname+' '+data.details.lastname+'</h2>');		
							
												// Entry image links															
												$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.headshot.src+'" class="selected" >View headshot</a></h3>');
												$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.threequarters.src+'">View bare-chested 3/4 shot</a></h3>');
												$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.profile.src+'">View Profile image</a></h3>');
												$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.fulllength.src+'">View full length shot</a></h3>');

												// fields that are visible to the public									
												$("#entryDetails").append('<h3><strong>Age: </strong>'+data.details.age+'</h3>');
												$("#entryDetails").append('<h3><strong>Height: </strong>'+data.details.height+'</h3>');																		
												$("#entryDetails").append('<h3><strong>Chest: </strong>'+data.details.chest+'</h3>');	
												$("#entryDetails").append('<h3><strong>Waist: </strong>'+data.details.waist+'</h3>');	
												$("#entryDetails").append('<h3><strong>Shoe: </strong>'+data.details.shoe+'</h3>');	
												$("#entryDetails").append('<h3><strong>Hair: </strong>'+data.details.hair+'</h3>');	
												$("#entryDetails").append('<h3><strong>Eyes: </strong>'+data.details.eyes+'</h3>');	

												// check if detail is available for special fields								
											    if(data.details.address1 !== undefined){
													$("#entryDetails").append('<h3><strong>Adress 1: </strong>'+data.details.address1+'</h3>');	
												}
											    if(data.details.address2 !== undefined){
													$("#entryDetails").append('<h3><strong>Adress 2: </strong>'+data.details.address2+'</h3>');	
												}	
											    if(data.details.town !== undefined){
													$("#entryDetails").append('<h3><strong>Town: </strong>'+data.details.town+'</h3>');	
												}
											    if(data.details.city !== undefined){
													$("#entryDetails").append('<h3><strong>City: </strong>'+data.details.city+'</h3>');	
												}
											    if(data.details.region !== undefined){
													$("#entryDetails").append('<h3><strong>Region: </strong>'+data.details.region+'</h3>');	
												}																						
											    if(data.details.zip !== undefined){
													$("#entryDetails").append('<h3><strong>Zip: </strong>'+data.details.zip+'</h3>');	
												}
											    if(data.details.country !== undefined){
													$("#entryDetails").append('<h3><strong>Country: </strong>'+data.details.country+'</h3>');	
												}							
												if(data.details.postcode !== undefined){
													$("#entryDetails").append('<h3><strong>Postcode: </strong>'+data.details.postcode+'</h3>');	
												}
											    if(data.details.telephone !== undefined){
													$("#entryDetails").append('<h3><strong>Telephone: </strong>'+data.details.telephone+'</h3>');	
												}	
											    if(data.details.email !== undefined){
													$("#entryDetails").append('<h3><strong>Email: </strong>'+data.details.email+'</h3>');	
												}

												/* This section throws an error in IE - go through it in details*/
												if (data.video !== undefined) {
													$("#video div").remove();
													$("#video").append('<div class="VideoPlayer"></div>');
													$('.VideoPlayer').attr('href', '/swf/mediaplayer_black.swf?file='+data.video.src+'&frontcolor=0xFFFFFF&screencolor=0xFFFFFF&autostart=true');	
													$('.VideoPlayer').media( {   width: 340, height: 210, params:{allowFullScreen:true}, bgColor:'#0F0F0F', flashVersion:'9'  });
												}else{
													$("#video div").remove();
												}

									    		$('#imageLinks a').click(function(){ 	$('#mainImg').attr('src', $(this).attr('title'));	$('#imageLinks a.selected').removeClass("selected");	 $(this).addClass("selected");	 });									

							});

						});	

			            // Prevent click eventpropagation
			            return false;
			        }

				if(!window.location.hash.replace(/#/,'')){
						currMemberId = members[0][3];	// get the latest user ID from the members array
				}else{
						currMemberId = window.location.hash.replace(/#/,'')	
				}
				
				$("#Pagination").pagination(members.length, {
					items_per_page:8, 
					num_edge_entries: 1,	
					num_display_entries: 4,									
					callback:pageselectCallback
				});

				// Event Handler for for button
				$("#setoptions").click(function(){

						$("#Pagination").pagination(members.length, {
							items_per_page:8, 
							num_edge_entries: 1,						
							num_display_entries: 4,									
							callback:pageselectCallback
						});

	            });
	
				var newJSON_URL = "/project/vmanmodelsearch/json/entry/"+currMemberId;

				$.getJSON(newJSON_URL,
					
				        function(data){
						
							$("#mainImg").attr('src', data.headshot.src);			
							$("#imageLinks h3").remove();
							$("#topEntryDetails h2").remove();																		
							$("#entryDetails p").remove();
							$("#entryDetails h2").remove();								
							$("#entryDetails h3").remove();	
							$("#entryDetails a").remove();	
							$("#entryDetails br").remove();	

							$("#topEntryDetails").append('<h2>'+data.details.firstname+' '+data.details.lastname+'</h2>');		

							// Entry image links															
							$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.headshot.src+'" class="selected" >View headshot</a></h3>');
							$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.threequarters.src+'">View bare-chested 3/4 shot</a></h3>');
							$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.profile.src+'">View Profile image</a></h3>');
							$("#imageLinks").append('<h3><a href="#'+currMemberId+'" title="'+data.fulllength.src+'">View full length shot</a></h3>');
							
							// fields that are visible to the public									
							$("#entryDetails").append('<h3><strong>Age: </strong>'+data.details.age+'</h3>');
							$("#entryDetails").append('<h3><strong>Height: </strong>'+data.details.height+'</h3>');																		
							$("#entryDetails").append('<h3><strong>Height: </strong>'+data.details.chest+'</h3>');	
							$("#entryDetails").append('<h3><strong>Waist: </strong>'+data.details.waist+'</h3>');	
							$("#entryDetails").append('<h3><strong>Shoe: </strong>'+data.details.shoe+'</h3>');	
							$("#entryDetails").append('<h3><strong>Hair: </strong>'+data.details.hair+'</h3>');	
							$("#entryDetails").append('<h3><strong>Eyes: </strong>'+data.details.eyes+'</h3>');	
																					
							// check if detail is available for special fields								
						    if(data.details.address1 !== undefined){
								$("#entryDetails").append('<h3><strong>Adress 1: </strong>'+data.details.address1+'</h3>');	
							}
						    if(data.details.address2 !== undefined){
								$("#entryDetails").append('<h3><strong>Adress 2: </strong>'+data.details.address2+'</h3>');	
							}	
						    if(data.details.town !== undefined){
								$("#entryDetails").append('<h3><strong>Town: </strong>'+data.details.town+'</h3>');	
							}
						    if(data.details.city !== undefined){
								$("#entryDetails").append('<h3><strong>City: </strong>'+data.details.city+'</h3>');	
							}
						    if(data.details.region !== undefined){
								$("#entryDetails").append('<h3><strong>Region: </strong>'+data.details.region+'</h3>');	
							}																						
						    if(data.details.zip !== undefined){
								$("#entryDetails").append('<h3><strong>Zip: </strong>'+data.details.zip+'</h3>');	
							}
						    if(data.details.country !== undefined){
								$("#entryDetails").append('<h3><strong>Country: </strong>'+data.details.country+'</h3>');	
							}							
							if(data.details.postcode !== undefined){
								$("#entryDetails").append('<h3><strong>Postcode: </strong>'+data.details.postcode+'</h3>');	
							}
						    if(data.details.telephone !== undefined){
								$("#entryDetails").append('<h3><strong>Telephone: </strong>'+data.details.telephone+'</h3>');	
							}	
						    if(data.details.email !== undefined){
								$("#entryDetails").append('<h3><strong>Email: </strong>'+data.details.email+'</h3>');	
							}

						    $('#imageLinks a').click(function(){ 	$('#mainImg').attr('src', $(this).attr('title'));	$('#imageLinks a.selected').removeClass("selected");	 $(this).addClass("selected");	 });									

							/* This section throws an error in IE - go through it in details*/
							if (data.video !== undefined) {
								$("#video div").remove();
								$("#video").append('<div class="VideoPlayer"></div>');
								$('.VideoPlayer').attr('href', '/swf/mediaplayer_black.swf?file='+data.video.src+'&frontcolor=0xFFFFFF&screencolor=0xFFFFFF&autostart=true');	
								$('.VideoPlayer').media( {   width: 340, height: 210, params:{allowFullScreen:true}, bgColor:'#0F0F0F', flashVersion:'9'  });
							}else{
								$("#video div").remove();
							}

				});
				
				// initialize google Stats
				$.gaTracker('UA-7210865-1');								
	
    });