
		var last_href = "";
		var timeout_timer = setTimeout("reloadLastCall();",5000);


		function langToggle(checkbox) {
			var counter =0;
			if($(checkbox).hasClass('item')) {
				//if this is the ALL button, remove all others
				if($(checkbox).attr('id') == "ALL") {
					$('.lang a.active').each(function(index) {
						$(this).removeClass('active').addClass('item');
					});
				}
				$(checkbox).removeClass('item').addClass('active');
				counter--;
			} else {
				$(checkbox).removeClass('active').addClass('item');
			}
			// remove the All or add the ALL if nothing is selected
			$('.lang a.active').each(function(index) {
				counter++;
			});
			if(counter == 0) {
				$(".lang #ALL").removeClass('item').addClass('active');
			} else {
				$(".lang #ALL").removeClass('active').addClass('item');
			}

			reloadHome();	
			return false;
		}



                function genderToggle(checkbox) {
                        counter =0;
                        if($(checkbox).hasClass('item')) {
                                $(checkbox).removeClass('item').addClass('active');
                        } else {
                                $(checkbox).removeClass('active').addClass('item');
                        }
                        // add the F if nothing is selected
                        $('.gender a.active').each(function(index) {
                                counter++;
                        });
                        if(counter == 0) {
                                $(".gender #F").removeClass('item').addClass('active');
                        } 

                        reloadHome();
                        return false;
                }



                function ageToggle(checkbox) {
                        var counter =0;
                        if($(checkbox).hasClass('item')) {
                                //if this is the ALL button, remove all others
                                if($(checkbox).attr('id') == "ALL") {
                                        $('.age a.active').each(function(index) {
                                                $(this).removeClass('active').addClass('item');
                                        });
                                }
                                $(checkbox).removeClass('item').addClass('active');
                                counter--;
                        } else {
                                $(checkbox).removeClass('active').addClass('item');
                        }
                        // remove the All or add the ALL if nothing is selected
                        $('.age a.active').each(function(index) {
                                counter++;
                        });
                        if(counter == 0) {
                                $(".age #ALL").removeClass('item').addClass('active');
                        } else {
                                $(".age #ALL").removeClass('active').addClass('item');
                        }

                        reloadHome();
                        return false;
                }

                function filterToggle(checkbox) {
                        if($(checkbox).hasClass('item')) {
                                $(checkbox).removeClass('item').addClass('active');
                        } else {
                                $(checkbox).removeClass('active').addClass('item');
                        }
                        reloadHome();
                        return false;
                }


		function reloadHome() {
			$('#ajaxcontainer').html('<img  style="padding-left:271px;padding-top:7px" src="/v2/Images/ajax.gif"/>');
			href = "?size=" + thumbsize + "&userlang=" + userlang;

			// Get lang
			var hreflang = "&lang=";
			$('.lang a.active').each(function(index) {
			 	if(index == 0) {
					hreflang = hreflang + $(this).attr('id');
				} else { 
					hreflang = hreflang + ',' + $(this).attr('id');
				}
  			});

			// Get gender
                        var hrefgender = "&gender=";
                        $('.gender a.active').each(function(index) {
                                if(index == 0) {
                                        hrefgender = hrefgender + $(this).attr('id');
                                } else {
                                        hrefgender = hrefgender + ',' + $(this).attr('id');
                                }
                        });

                        // Get age
                        var hrefage = "&age=";
                        $('.age a.active').each(function(index) {
                                if(index == 0) {
                                        hrefage = hrefage + $(this).attr('id');
                                } else {
                                        hrefage = hrefage + ',' + $(this).attr('id');
                                }
                        });

                        var hreffilter = "&filter=";
                        $('.filter a.active').each(function(index) {
                                if(index == 0) {
                                        hreffilter = hreffilter + $(this).attr('id');
                                } else {
                                        hreffilter = hreffilter + ',' + $(this).attr('id');
                                }
                        });



			href = href + hreflang + hrefgender + hrefage + hreffilter;


			last_href = href;
			clearTimeout(timeout_timer);
			timeout_timer = setTimeout("reloadLastCall();",5000);


			savePrefs();
			// go find all active items and create URL
			$.getJSON('/v2/ajax.php' + href, function(data) {
				$('#ajaxcontainer').html(data.html);
			});
			return false;
		}



		// 
		function reloadLastCall() {
                       	$('#ajaxcontainer').html('<img  style="padding-left:271px;padding-top:7px" src="/v2/Images/ajax.gif"/>');

                        $.getJSON('/v2/ajax.php' + last_href, function(data) {
                                $('#ajaxcontainer').html(data.html);
                        });

                        return false;

		}


                function reloadPage(href) {
	                        $('#ajaxcontainer').html('<img  style="padding-left:271px;padding-top:7px" src="/v2/Images/ajax.gif"/>');

                        $.getJSON('/v2/ajax.php' + href, function(data) {
                                $('#ajaxcontainer').html(data.html);
                        });
                        return false;
                }

                function savePrefs() {
                        var checkbox;
                        $('.lang a.active').each(function(index) {
                                if(index == 0) {
                                        checkbox = '.lang #' + $(this).attr('id');
                                } else {
                                        checkbox = checkbox + ':.lang #' + $(this).attr('id');
                                }
                        });

                        $('.gender a.active').each(function(index) {
                                        checkbox = checkbox + ':.gender #' + $(this).attr('id');
                        });

                        $('.age a.active').each(function(index) {
                                        checkbox = checkbox + ':.age #' + $(this).attr('id');
                        });



                        createCookie('checkbox',checkbox,356);
                }

                function reloadPrefs() {
                        var checkbox = readCookie('checkbox');
                        if(checkbox != null) {
                                // reset all boxes , and then activate those saved
                                $('.lang a.active').each(function(index) {
                                        $(this).removeClass('active').addClass('item');
                                });
                                $('.gender a.active').each(function(index) {
                                        $(this).removeClass('active').addClass('item');
                                });
                                $('.age a.active').each(function(index) {
                                        $(this).removeClass('active').addClass('item');
                                });

                                var ca = checkbox.split(':');
                                for(var i=0;i < ca.length;i++) {
                                        var c = ca[i];
                                        $(c).removeClass('item').addClass('active');
                                }
                                reloadHome();
                        }
                }


