$(document).ready(function() {
	
	//Cursor focus on Main Search
	document.frmGeneralSearch.criteria.focus();
    
	//builds numberplates with reg font
	       $(".numberplate").html(function(i, h) {
           return h.replace(/([a-z0-9])/ig, '<img src="/images/rt-auction/plate-builder/$1.gif" />');
       });
	
	//DVLA Auction Widget
    function tweet() {
        $("#tweet li:last").hide().addClass('new-item').prependTo("#tweet").slideDown(300);
        $('.new-item').css({
            'opacity': '0',
            'filter': 'alpha(opacity=0)'
        }).animate({
            opacity: '1'
        },
        function() {
            $(this).removeClass('new-item')
        });
    };
    setInterval(tweet, 3500);
	
	//Auction Widget
    function featPlate() {
        $("#featPlate li:last").hide().addClass('new-item').prependTo("#featPlate").slideDown(300);
        $('.new-item').css({
            'opacity': '0',
            'filter': 'alpha(opacity=0)'
        }).animate({
            opacity: '1'
        },
        function() {
            $(this).removeClass('new-item')
        });
    };
    setInterval(featPlate, 4000);


/*
	//Celebrity Pic Widget
	var links = new Array();
	var celebs=["paphitas:t1heo", "bannatyne:23d", "caan:28jc", "jones:100vj", "botham:b33fys", "khan:box111g", "moss:sm7", "tarrant:chu8b",   "martin:6hef","clarke:h41rdo", "humperdinck:eh1", "walsh:mrd1y", "sanderson:5tes", "daniels:mag1c", "fullerton:fiona"];
	var celebweight=[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; //weight of each celeb above
	var totalweight=eval(celebweight.join("+")); //get total weight 
	var weighedcelebs=new Array(); //new array to hold "weighted" celebs
	var currentceleb=0;
	
	while (currentceleb<celebs.length){ //step through each celeb[] element
		for (i=0; i<celebweight[currentceleb]; i++)
			weighedcelebs[weighedcelebs.length]=celebs[currentceleb];
		
		currentceleb++;
	}
	
	var randomnumber=Math.floor(Math.random()*totalweight);
	var celeblink = weighedcelebs[randomnumber];
	var celeb = celeblink.split(":");
	
	
	var html = '<div id="celebrity"><a href="http://www.regtransfers.co.uk/main/stories/' + celeb[1] + '.asp"><img src="/images_new/rotatingCelebs/'+ celeb[0] +'.jpg" title="' + celeb[0] + '" alt="celebrities" width="441" height="175" border="0"></a></div><div style="margin-top:5px; text-align:center;" id="dem-links">';
	var o = document.getElementById('my-celeb');

	html += '</div>more &raquo;';
	for (var j=0; j<15; j++){
		
		var clink = celebs[j].split(":");
		html += '<a href="#" class="celeb-link" title="View other celebrities" onclick="changePic('+ j + ', \'' + clink[1] + '\', \'' + clink[0] +'\');">'+ (j+1) +'</a>';
	}	
	o.innerHTML  = html;
	*/
	
	//Modal Window
  //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect     
        $('#mask').fadeIn(1000);    
        $('#mask').fadeTo("slow",0.8);  
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000); 
     
    });
     
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });     
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    }); 
	
});

function genCelebWidget() {
	var links = new Array();
	var celebs=["paphitas:t1heo", "bannatyne:23d", "caan:28jc", "jones:100vj", "botham:b33fys", "khan:box111g", "moss:sm7", "tarrant:chu8b",   "martin:6hef","soloman:sx10bug_111115", "nolan:cno14n_110322", "dettori:60fd_010710", "tufnell:be57cat_101115", "mae:v1mae_010310", "haye:dd11aye_110712"];
	var celebweight=[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; //weight of each celeb above
	var totalweight=eval(celebweight.join("+")); //get total weight 
	var weighedcelebs=new Array(); //new array to hold "weighted" celebs
	var currentceleb=0;
	
	while (currentceleb<celebs.length){ //step through each celeb[] element
		for (i=0; i<celebweight[currentceleb]; i++)
			weighedcelebs[weighedcelebs.length]=celebs[currentceleb];
		
		currentceleb++;
	}
	
	var randomnumber=Math.floor(Math.random()*totalweight);
	var celeblink = weighedcelebs[randomnumber];
	var celeb = celeblink.split(":");
	
	
	var html = '<div id="celebrity"><a href="http://www.regtransfers.co.uk/number-plates-stories/' + celeb[1] + '.asp"><img src="/images_new/rotatingCelebs/'+ celeb[0] +'.jpg" title="' + celeb[0] + '" alt="celebrities" width="441" height="175" border="0"></a></div><div style="margin-top:5px; text-align:center;" id="dem-links">';
	var o = document.getElementById('my-celeb');

	html += '</div>more &raquo;';
	for (var j=0; j<15; j++){
		
		var clink = celebs[j].split(":");
		html += '<a href="#" class="celeb-link" title="View other celebrities" onclick="changePic('+ j + ', \'' + clink[1] + '\', \'' + clink[0] +'\');">'+ (j+1) +'</a>';
	}	
	o.innerHTML  = html;	
}

function changePic(picNum, celebLnk, celebNew){
	document.getElementById("celebrity").innerHTML = '<a href="http://www.regtransfers.co.uk/number-plates-stories/' + celebLnk + '.asp"><img src="/images_new/rotatingCelebs/'+ celebNew +'.jpg" title="' + celebNew + '" alt="celebrities" width="441" height="175" border="0"></a>';
}


