$(function(){ 
	
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	
	if($.browser.mozilla||$.browser.safari){ //only let Firefox and Safari have rounded corners
		if(!is_chrome) { // Make sure chrome get's kicked in the balls
			$('#header #nav').corners("10px transparent right");
			$('#top-box #content').corners("10px transparent left");
			$('#content a.past-contests').corners("8px transparent");
			$('#top-box #product-preview').corners("10px transparent");
			$('#sponsors .sponsor').corners("10px transparent");
			$('#tab-headers .active').corners("10px transparent top");
			$('#tab-headers .active').live('click', function(){$(this).corners("10px transparent top");});
			$('#tab-holder #comments-tab').corners("10px transparent");
			$('#tab-holder #review-tab').corners("10px transparent");
			$('#tab-holder #description-tab').corners("10px transparent right bottom-left");
			$('#contests .preview').corners("10px transparent");
			$('.product-thumb a').corners("10px transparent");
			$('body #footer').corners("10px transparent");
			$('.sponsor-block img').corners("10px transparent");
			$('#tab-holder #lower-content').corners("10px transparent");
			$('#comments .reply').corners("10px transparent");
			$('.reply .vcard').corners("10px transparent top");
		}
	}
	
	function isOdd(number){
		if (number%2 == 0) return true; // number's odd
		else return false; // number's even
	};
	
	var number_of_contests = $('.past-contests-list ul').length;
	if(number_of_contests > 0){
		if (isOdd(number_of_contests)) {
			if($.browser.mozilla||$.browser.safari){
				if(!is_chrome) {
					$('.past-contests-list ul:odd').corners("10px transparent");
				}
			}
			$('.past-contests-list ul:odd').addClass('odd');
		}
		else {
			if($.browser.mozilla||$.browser.safari){
				if(!is_chrome) {
					$('.past-contests-list ul:even').corners("10px transparent");
				}
			}
			$('.past-contests-list ul:even').addClass('odd');
		}
	}
	
	var number_of_winners = $('#winners li').length;
	if(number_of_winners > 0){
		if (isOdd(number_of_winners)) {
			if($.browser.mozilla||$.browser.safari){
				if(!is_chrome) {
					$('#winners li:odd').corners("10px transparent");
				}
			}
			$('#winners li:odd').addClass('odd');
		}
		else {
			if($.browser.mozilla||$.browser.safari){
				if(!is_chrome) {
					$('#winners li:even').corners("10px transparent");
				}
			}
			$('#winners li:even').addClass('odd');
		}
	}
	
	$('#thumbs a').fancybox();
	
	$('#top-box a.comment').click(function(){
		$('#tab-headers a:eq(2)').trigger('click');
		$("#tab-wrap #comments-tab").removeClass('height-fix');
	});
	
	$("#tab-headers a").click(function(){
		$("#left-col #tab-headers").find('a').removeClass('active');
		$(this).addClass('active');
		if( $('#tab-headers a:eq(2)').hasClass('active') ){
			$('#left-col #tab-headers').css('paddingLeft' , '6px');
			$("#tab-wrap #comments-tab").removeClass('height-fix');
			$("#tab-wrap #description-tab").addClass('height-fix');
		}
		if( $('#tab-headers a:eq(1)').hasClass('active') ){
			$('#left-col #tab-headers').css('paddingLeft' , '6px');
			$("#tab-wrap #review-tab").removeClass('height-fix');
			$("#tab-wrap #description-tab").addClass('height-fix');
		}
		if( $('#tab-headers a:eq(0)').hasClass('active') ){
			$('#left-col #tab-headers').css('paddingLeft' , '0px');
			$("#tab-wrap #comments-tab").addClass('height-fix');
			$("#tab-wrap #review-tab").addClass('height-fix');
			$("#tab-wrap #description-tab").removeClass('height-fix');
		}
	});
		
	if($.browser.msie){
		$("#tab-wrap").find('.tab-content').hide();
		$('#tab-wrap #description-tab').show();
		$('#tab-wrap #lower-content').show();
		$('#tab-headers a:eq(1)').click(function(){
			$('#tab-wrap #description-tab').hide();
			$('#tab-wrap #comments-tab').hide();
			$('#tab-wrap #review-tab').show();
		});
		$('#tab-headers a:eq(2)').click(function(){
			$('#tab-wrap #description-tab').hide();
			$('#tab-wrap #review-tab').hide();
			$('#tab-wrap #comments-tab').show();
		});
		$('#tab-headers a:eq(0)').click(function(){
			$('#tab-wrap #description-tab').show();
			$('#tab-wrap #comments-tab').hide();
			$('#tab-wrap #review-tab').hide();
		});
		
		if($.browser.version < 8){
			$('#content .past-contests-list .contest-block:eq(0)').css('marginLeft' , '15px');
		}
	}
	
	if($.browser.mozilla){ // fix Firefox position issues
		$("#header #nav").css('marginTop' , '-62px');
	}
	
	if(!get_cookie('attention3')){ // hide the attention box if cookie is there
		$('body #attention-holder').append('<div class="attention"><p>Do you sell a product or service? Get your company featured by buying a day. <a href="http://anyluckyday.com/calendar">Cick here to sponsor now!</a></p> <a title="Don\'t show this notice again" class="close">&nbsp;</a></div>');
		if($.browser.mozilla||$.browser.safari){ //only let Firefox and Safari have rounded corners
			if(!is_chrome) { // Make sure chrome get's kicked in the balls
				$('#attention-holder .attention').corners("10px transparent");
			}
		}
		
		$('.attention .close').click(function(){ // close the attention box and set the cookie
			set_cookie('attention3', 'hide', '2020', '12', '31', '/')
			$('.attention').hide();
		});
	}
	
	$('#cse-search-results iframe').attr('width','624px');
	
	$('#comments label').inFieldLabels();
	
});

var commentsExp = new RegExp( "#comment" );
if ( window.location.href.search( commentsExp ) != -1 ) {
	$(function(){ 
		$("#tab-headers a:eq(2)").trigger('click');
		$("#tab-wrap #comments-tab").removeClass('height-fix');
	});
}

var reviewExp = new RegExp( "#review-tab" );
if ( window.location.href.search( reviewExp ) != -1 ) {
	$(function(){ 
		$("#tab-headers a:eq(1)").trigger('click');
		$("#tab-wrap #review-tab").removeClass('height-fix');
	});
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y ) {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path ) cookie_string += "; path=" + escape ( path );
  if ( domain ) cookie_string += "; domain=" + escape ( domain );
  if ( secure ) cookie_string += "; secure";
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name ) {
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results ) return ( unescape ( results[2] ) );
  else return null;
}