	 
var VW = function () {

	// bust out of any framesets before we do anything else
	if (top.location != self.location) {
		top.location.replace(self.location);
	}

	var mediaCom = {
		"/":					"type=polot274;cat=timel534;",
/* Category pages */
		"/tv": 		        	"type=polot274;cat=timel571;",
		"/food":				"type=polot274;cat=timel847;",
		"/music":				"type=polot274;cat=timel231;",
		"/design":				"type=polot274;cat=timel460;",
		"/fashion":				"type=polot274;cat=timel027;",
/* Channel landing pages */
		"/all/thankyou":		"type=polot274;cat=thank935;",
		"/tv/thankyou":			"type=polot274;cat=signu227;",
		"/food/thankyou":		"type=polot274;cat=signu867;",
		"/design/thankyou":		"type=polot274;cat=signu814;",
		"/music/thankyou":		"type=polot274;cat=signu673;",
		"/fashion/thankyou":	"type=polot274;cat=signu886;",
/* Popups */
		"/about":				"type=polot274;cat=start640;",
		"/comment":				"type=polot274;cat=comme051;",
		"/commentSubmit":		"type=polot274;cat=comme235;",
		"/voteThanks":			"type=polot274;cat=thank872;",
/* Signup channels */
		"/signup/tv":			"type=polot274;cat=signu012;",
		"/signup/food":			"type=polot274;cat=signu021;",
		"/signup/music":		"type=polot274;cat=signu661;",
		"/signup/design":		"type=polot274;cat=signu568;",
		"/signup/fashion":		"type=polot274;cat=signu901;",
/* Other pages */
		"/signup":				"type=polot274;cat=signu322;",
		"/signup/thankyou":		"type=polot274;cat=signu598;",
		"/explore":				"type=polot274;cat=polop524;",
		"/events":				"type=polot274;cat=event182;"
    };

	var trackData = {},
		campaignId = "",
		referrer = "";


	function initHTML() {
		$(document).ready(function () {
			
			// Expand Panel
			$("#open").click(function(){
				$("div#userCredits").slideDown("slow");	
				return false;
			});	
		 
			// Collapse Panel
			$("#close").click(function(){
				$("div#userCredits").slideUp("slow");	
				return false;
			});		
		 
			// Switch buttons
			$("#toggle a").click(function () {
				$("#toggle a").toggle();
				return false;
			});	
			

		    $('.infiniteCarousel').infiniteCarousel();


			track(window.location.pathname);
			
			var hide = false;
			var itemId;
			
			$(".itemInfo").hover(function(){
				
				$(".itemDesc").fadeOut(500);
				if (hide) clearTimeout(hide);
				itemId = $(this).attr('id')


			$("#i"+itemId).fadeIn();
			}, function() {
				hide = setTimeout(function() {$("#i"+itemId).fadeOut(500);}, 150);
			});
			
			$(".itemDesc").hover(function(){
				if (hide) clearTimeout(hide);
			}, function() {
				hide = setTimeout(function() {$("#i"+itemId).fadeOut(500);}, 150);
			});
			
			$("#inviteFriend form input#send").click(function() {
				track("/earn/sendToFriend");
			});
			
		});
	}



// Carousel	
$.fn.infiniteCarousel = function () {

		    function repeat(str, num) {
			return new Array( num + 1 ).join( str );
		    }
		  
		    return this.each(function () {
			var $wrapper = $('> div', this).css('overflow', 'hidden'),
			    $slider = $wrapper.find('> ul'),
			    $items = $slider.find('> li'),
			    $single = $items.filter(':first'),
			    
			    singleWidth = $single.outerWidth(), 
			    visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
			    currentPage = 1,
			    pages = Math.ceil($items.length / visible);            
    

			//  Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
			$items.filter(':first').before($items.slice(- visible).clone());
			$items.filter(':last').after($items.slice(0, visible).clone());
			$items = $slider.find('> li'); // reselect
			
			// Set the left position to the first 'real' item
			$wrapper.scrollLeft(singleWidth * visible);
			
			//  paging function
			function gotoPage(page) {
			    var dir = page < currentPage ? -1 : 1,
				n = Math.abs(currentPage - page),
				left = singleWidth * dir * visible * n;
			    
			    $wrapper.filter(':not(:animated)').animate({
				scrollLeft : '+=' + left
			    }, 600, function () {
				if (page == 0) {
				    $wrapper.scrollLeft(singleWidth * visible * pages);
				    page = pages;
				} else if (page > pages) {
				    $wrapper.scrollLeft(singleWidth * visible);
				    // reset back to start position
				    page = 1;
				} 

				currentPage = page;
			    });                
			    
			    return false;
			}
			
			$wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
			
			//  Bind to the forward and back buttons
			$('a.back', this).click(function () {
			    return gotoPage(currentPage - 1);                
			});
			
			$('a.forward', this).click(function () {
			    return gotoPage(currentPage + 1);
			});
			
			// create a public interface to move to a specific page
			$(this).bind('goto', function (event, page) {
			    gotoPage(page);
			});
		    });  
		};



	/* Tracking */

	function track(url) {

        log("tracking: " + url);

        // omniture
		doOmnitureTracking(url);

		// media com tracking tags
		if (mediaCom[url]) {
			log("mediacom: " + url + ' = "' + mediaCom[url] + '"');
			var axel = Math.random() + "";
			var a = axel * 10000000000000;
			$("body").append('<iframe src="//fls.doubleclick.net/activityi;src=1822532;' + mediaCom[url] + 'ord=1;num='+ a + '?" width="1" height="1" frameborder="0"></iframe>');
		}

    }

	function doOmnitureTracking(url, configDetails) {

		s.pageName = url;
		s.trackFormList = false;
        s.g = document.location.hostname + url

        setOmnitureProperties(url, configDetails);

		var s_code = s.t();
		if (s_code) $("body").append(s_code);
	}

	function setOmnitureProperties(url, configDetails) {

        // channel
        s.channel = url;

        // server
        s.server = document.location.hostname;
    }
    
    function log(str) {
		if (window.location.hostname != "www.timeless50.com" && typeof console != "undefined" && typeof console.log == "function") console.log(str);
	}

	return {
		initHTML: initHTML,
        track: track,
        log: log
	};
}();

function findAddress() {

    var postcode = $("input#postcode").val().replace(/ /g, '');

    $.get("/postcode/find", {
        postcode: postcode
    }, function(xml) {

        var street = $(xml).find('street').text();

        if (street.length > 0) {

            // Clear error message area
            $(".addressError").html("");
            $("input#street1").val(street);
            var street2 = $(xml).find('street2').text();
            $("input#street2").val(street2);
            var city = $(xml).find('city').text();
            $("input#city").val(city);
            var county = $(xml).find('county').text();
            $("input#county").val(county);
            var postcode = $(xml).find('postcode').text();
            $("input#postcode").val(postcode);

        } else {

            var postcode = $("input#postcode").val()

            if (postcode) {
                $("#findAddressError").html("Postcode not found");
            } else {
                $("#findAddressError").html("Please enter a postcode");
            }
        }
    });
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}