var javascript_countdown = function () {
	var time_left = 10; //number of seconds for countdown
	var output_element_id = 'javascript_countdown_time';
	var keep_counting = 1;
	var no_time_left_message = 'No time left for JavaScript countdown!';
 
	function countdown() {
		if(time_left < 2) {
			keep_counting = 0;
		}
 
		time_left = time_left - 1;
	}
 
	function add_leading_zero(n) {
		if(n.toString().length < 2) {
			return '0' + n;
		} else {
			return n;
		}
	}
 
	function format_output(thepart) {
		var hours, minutes, seconds;
		seconds = time_left % 60;
		minutes = Math.floor(time_left / 60) % 60;
		hours = Math.floor(time_left / 3600);
 
		seconds = add_leading_zero( seconds );
		minutes = add_leading_zero( minutes );
		hours = add_leading_zero( hours );
 
 		if (thepart == 'hours') {
			return hours + '<br><span>hrs</span>';	
		} else if (thepart == 'mins') {
			return minutes + '<br><span>mins</span>';
		} else if (thepart == 'secs') {
			return seconds + '<br><span>secs</span>';	
		} else {
		return hours + ':' + minutes + ':' + seconds;
		}
	}
 
	function show_time_left() {
		$('#' + output_element_id + ' .hours').html(format_output('hours'));//time_left;
		$('#' + output_element_id + ' .mins').html(format_output('mins'));//time_left;
		$('#' + output_element_id + ' .secs').html(format_output('secs'));//time_left;
	}
 
	function no_time_left() {
		time_left = 86400;
		//document.getElementById(output_element_id).innerHTML = no_time_left_message;
	}
 
	return {
		count: function () {
			countdown();
			show_time_left();
		},
		timer: function () {
			javascript_countdown.count();
 
			if(keep_counting) {
				setTimeout("javascript_countdown.timer();", 1000);
			} else {
				no_time_left();
			}
		},
		//Kristian Messer requested recalculation of time that is left
		setTimeLeft: function (t) {
			time_left = t;
			if(keep_counting == 0) {
				javascript_countdown.timer();
			}
		},
		init: function (t, element_id) {
			time_left = t;
			output_element_id = element_id;
			javascript_countdown.timer();
		}
	};
}();

$( function(){
    $( '.ds-deal-media' ).hover( function(){
        $( '.ds-deal-media ul' ).stop(1).animate({'right':'-85px'}, 'normal' );
    }, function(){
        $( '.ds-deal-media ul' ).stop(1).animate({'right':'10px'}, 'normal' );
    } );
    $( '.ds-deal-media ul li' ).hover( function(){
        $( '.ds-deal-media > img' ).attr( 'src', $( this ).children().attr( 'data-fullsrc' ) );
    } );

    $( '.rfloat .slideshow li img' ).hover( function(){
        var src = $( this ).attr( 'src' ).split( '/' );
        src[ src.length - 2 ] = 'large';
        $( '.rfloat img.main' ).attr( 'src', src.join( '/' ) );
    } );
} );

