// prototypes
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


// document is ready
$(document).ready(function() {
	var bsa = document.createElement('script');
	bsa.type = 'text/javascript';
	bsa.async = true;
	bsa.src = '//s3.buysellads.com/ac/bsa.js';
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
	
	$('a[rel="external"]').attr('target','_blank').removeAttr('rel');
	
	$('#input_search').click(function() {
		$('input', this).focus();
	});
	if(navigator.userAgent.match(/iPad/i) == null){
		$('.wallpapers dd .thumb, .wallpapers_large dd .thumb')
		.bind('mouseenter', function() {
			$('.title', this).slideDown('fast');
		})
		.bind('mouseleave', function() {
			$('.title', this).slideUp('fast');
		});
	}
		
	// $.jquery.countdown('');
	countdown();
	
	$('#search').keypress(function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code == 13) {
			searchKeyword($(this).val());
		}
	});
	$('#go_btn').click(function() {
		searchKeyword($('#search').val());
		return false;
	});
});


// functions
function countdown()
{
	var ct = new Date();
	var hours = ct.getHours();
	var mins = ct.getMinutes();
	var secs = ct.getSeconds();

	var cdHours = 23 - hours;
	var cdMins = 59 - mins;
	var cdSecs = 59 - secs;
	
	var count = '';
	(cdHours != 0) ? count += cdHours+' hours ' : '' ;
	(cdMins != 0) ? count += cdMins+' minutes ' : '' ;
	count += cdSecs+' seconds';
	
	if(cdHours == 0 && cdMins == 0 && cdSecs == 0){
		location.reload();
		return;	
	}
	
	$('#status_bar .countdown').html(count);
	
	var secsTotal = 24*60*60;
	var secsRemain = (cdHours*60*60)+(cdMins*60)+cdSecs;
	var percent = Math.abs((secsRemain / secsTotal)-1);
	var filler = Math.floor($('#status_bar').innerWidth() * percent);
	$('#status_bar .filler').width(filler);
	
	setTimeout(countdown, 1000);
}

function searchKeyword(keyword)
{
	if(keyword != ''){
		window.location = base_url+'search/'+keyword;
	}
}

/*
(function($){
	$.fn.jquery.countdown({
		countdown: function(options) {
			
			var defaults = {  
				timer: 1,
			};
			
			return this.each(function() {  
 				var obj = $(this);
				
				var ct = new Date();
				var hours = ct.getHours();
				var mins = ct.getMinutes();
				var secs = ct.getSeconds();

				var cdHours = 23 - hours;
				var cdMins = 59 - mins;
				var cdSecs = 59 - secs;
				
				
				$(this).html(cdHours+' hours '+cdMins+' minutes '+cdSecs+' seconds');
			});
		}
		setTimeout(countdown, (timer * 1000));
	});          
})(jQuery);
*/
