function bookmarksite(){
		var title = document.title;
		var url = location.href.replace(/\.htm#?$/i, '');
		if (window.sidebar) // firefox
			window.sidebar.addPanel(title, url, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else if(document.all)// ie
			window.external.AddFavorite(url, title);
	};
function formValidate($thisForm){
		var $fields = $thisForm.find('input[type=text], input[type=password], textarea').not('.ffv-opt');
		
		var validate = true;
		$fields.each(function(){
			var email_filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
			var v = 1;
			if ($(this).attr('name') == 'email' || $(this).attr('name') == 'e-mail') {
				if (!email_filter.test($(this).val())) {
					validate = false;
					v = -1;
				}
			}
			if (!$(this).val() || $(this).val() == '' || $(this).val() == $(this).get(0).defaultValue) {
				validate = false;
				v = -1;
			}
			if (v == -1) {
				$(this)
					.addClass('ff-notvalid')
					.bind("focus", function(){
						$(this).removeClass('ff-notvalid');
					});
			}
		})
		
		if (validate) {return true;}
		return false;
}

$(document).ready(function(){
	/* JS - NOJS */
	$('.container').attr("id", 'js');
	
	$('.colorbox-screenshot').each(function(){
		$(this).colorbox({transition:"elastic", opacity:"0.8"}, function(){
			if ($(this).siblings('.game-rev-buttons').length>0) {
				var append_h1 = $('.center h1').text();
				var append_partner = $('.game-rev-buttons .golden-but17').attr('href');
				$('.center').append('<div class="screen_appendix"><a target="_blank" href="'+append_partner+'"><span><span>Play '+append_h1+'</span></span></a></div>');
				var append_width = $('#cboxWrapper').width();
				$('.screen_appendix')
					.clone()
					.appendTo('#cboxBottomCenter')
					.addClass('shown')
					.css({'width':''+append_width+'px', 'top':'0', 'left':'0'})
					.show();
				$().bind("cbox_closed",function() { 
					$('.screen_appendix').remove();
				}); 
			}
		});
	});
	/* GREY ODDITY IN TABLES */
	$('.grey_block_table').not('.vertical').find('tr:odd').addClass('grey_table_odd');
	$('.vertical tr').each(function(){
		$(this).find('td:odd').addClass('grey_table_odd_v');
	});
	
	$('.grey_block_table').each(function(){
		$(this).find('tr:last').addClass('trlast');
	});
	
	/* GREY TABLE MANIPULATION */
	$('.grey_block').each(function() {
		var tableW = $(this).find('.grey_block_table').outerWidth(true);
		$(this).find('.grey_header').width(tableW-6);
	});
	/* CHARTS MANIPULATIONS */
	$('.chart_floated_l, .chart_floated_r').each(function(){
		var tableH = $(this).find('.chart').outerHeight(true);
		var tableW = $(this).find('.chart').outerWidth(true)
		$(this).find('.chart_header_v > div').height(tableH-16);
		$(this).width(tableW+19);
	})
	
	/* FAQ slidedown */
	$('.faq dd').hide();
	$('.faq dt a').click(function(ev){
		ev.preventDefault();
		$(this).parent('dt').next('dd').slideToggle('fast');
	});

	$('.sc_list_head').each(function(){
		var sc_lis = $(this).next('.sc_list').find('li');
		if (sc_lis.length == 0) {
			$(this).hide();
			$(this).next('.sc_list').hide();
		}
	});


	/* newpage */
	/*$('.main_menu li a[href*="blackjack-games"]').parent('span').addClass('mm-icon newpage');*/
	/* hot */
	$('.main_menu li a[href*="blackjack-cheatsheet"], li a[href*="free-blackjack"]').parent('span').addClass('mm-icon hotpage');
	/* tool */
	$('.main_menu li a[href$="blackjack-advisor.htm"], li a[href*="strategy-calculator"], li a[href*="edge-calculator"]').parent('span').addClass('mm-icon toolpage');
	/* upd */
	/*$('.main_menu li a[href*="blackjack-card-counting"],.main_menu li a[href*="blackjack-rules.htm"]').parent('span').addClass('mm-icon updpage');*/
	
	
	/* cruel fix */
	var lwH = $('.leftwrapper').height();
	var rwH = $('.right').height();
	if (lwH < rwH) $('.leftwrapper').height(rwH);
	$('.rules_form_chapter input[type="hidden"]').hide();
	$('.advisor_js').css('display', 'block');
	
	/* games drop menu */
	$('.game_daddy').each(function(){
		$('.game_daddy > a').hover(
			function() {
				$(this).next('ul').css('display', 'block');
			},
			function() {
				$(this).next('ul').css('display', 'none');
			});
	});
	
	/* game bottom form ajax */
	$('#gmbt-fsubmit').click(function(e){
		e.preventDefault();
		var $thisForm = $(this).parent('.gmbt-fform');
		var gfName = $thisForm.find('.gmbt-fname').val();
		var gfEmail = $thisForm.find('.gmbt-femail').val();
		var gfText = $thisForm.find('textarea').val();
		var gfSubj = $thisForm.find('input[name=subject]').val();
		
		if (formValidate($thisForm)) {
			$.post('thanks-feedback.htm', {
			name: gfName,
			email: gfEmail,
			content: gfText,
			subject: gfSubj
		}, function(){
			if (!gfName || gfName==$thisForm.find('.gmbt-fname').get(0).defaultValue)
			{gfName = 'visitor'}
			var txt = '<h3>Thank you!</h3><p>Dear ';
			txt+=gfName;
			txt+=', thank you for your help! Our specialists will deal with your letter in the shortest time and you will be sent a reply if you submitted an e-mail.</p>';
			$('.gmbt-feedback').html(txt);
		}, 'html');
		}
		return false;
	})
	
	/* form focus */
	$('.gmbt-fform textarea, .gmbt-fform input[type=text]').focus( function(){
		if (this.defaultValue == $(this).val())
			{$(this).css('color', '#333').val('').css('border-color', '');}
	});
	$('.gmbt-fform textarea, .gmbt-fform input[type=text]').blur( function(){
		if ($(this).val() == '')
			  {$(this).css('color', '#999').val(this.defaultValue);}
	});

	/* Newsletter old 
	$('.newsletter_form form').submit(function(e){
		e.preventDefault();
		var nfName = $(this).find('#nl_name').val();
		var nfEmail = $(this).find('#nl_email').val();
		if (formValidate($(this))) {
		$.post ('thanks-subscription.htm', {
			name: nfName,
			email: nfEmail
		}, function(){
		if (!nfName || nfName=='')
			{nfName = 'visitor'}
			var txt = '<h2>Thank you for subscription!</h2><p>Thank you for subscribing! You will receive our latest updates, information about new games, videos and new casinos!</p>';
			$('.newsletter_form').html(txt);
		}, 'html');
		}
		return false;
	});
*/


	/* newsletter */	
	$('.newsletter_form form').submit(function(e){
		e.preventDefault();
		
		var email_filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var formIsValid = true;
		
		$(this).find('.input input').each(function(){
			$(this).parents('.input').find('.error').remove();
			
			if($(this).hasClass('required') && ($(this).val() == '')){
				$(this).parents('.input').append('<div class="error">This field is required</div>')
				formIsValid = false;
			}
			if($(this).hasClass('email') && (!email_filter.test($(this).val()))){
				$(this).parents('.input').append('<div class="error">You should type a valid email</div>')
				formIsValid = false;
			}
		})
		
		if(!formIsValid){
			return false;
		}
		var action = $(this).attr('action');
		$.post (action, $(this).serialize(), function(data,status){
			if(status=='success'){
				data = eval(data.substring(1));
				var txt='Something goes wrong';
				if(data.result !='success'){
					txt = data.msg;
				} else {
					txt = '<h2>Thank you for subscription!</h2><p><strong>We need to confirm your email address.</strong> To complete the subscription process, please click the link in the email we just sent you.</p><p>Then you will receive our latest updates, information about new games, videos and new casinos.</p>';
				}
				$('.newsletter_form').html(txt);
			}
		}/*, 'json'*/);
		
		return false;
	});





	
	/* current screen */
	$('.current_res').each(function(){
		$(this).find('span').html(screen.width+'x'+screen.height);							
	});
	
	/* house edge calc mega table */
	$('.calc_odds_hand tr').find('td:first, th:first').addClass('first');
	$('.calc_odds_hand tr').find('td:last, th:last').addClass('last');
	
	/* Google Analytics goals */
	$('a[href^=to/]').attr('target', '_blank').click(function(){
		var href = $(this).attr('href');
		if (typeof(_gaq)!='undefined' && href.indexOf('//casino/')==-1) {
			trackPageview('click/'+href.replace(/http:\/\/[^\/]+\/[^\/]+/i, ''));
		}
		return true;
	});
	$('a[href^=http]').attr('target', '_blank');
	
	/* press tabs */
	$('.press_tab').click(function(){
	if ($(this).hasClass('active') == true)
		{}
		else
		{$('.press_tab, .press_head .seeall_link, .press_wrap').toggleClass('active');}
	});
	
	/* common tabs */
	$('.cmn_tabs').not('.cmn-not').each(function(){
		var $tabs = $(this).parent('div');
		$(this).find('a')
		.each(function(){
			$(this).parent('td').width($(this).parent('td').width());
		})
		.click(function(e){
			e.preventDefault();
			if(!$(this).is('.active')) {
				var cmntab = $(this).attr('href').substr(1);
				$tabs.find('.cmn_tabs').find('.active').removeClass('active')
				$(this).addClass('active');
				$tabs.find('.cmn_tabs_wrap .active').removeClass('active');
				$tabs.find('.cmn_tabs_wrap #'+cmntab+'').addClass('active');
			}
				
		})
	});
	
	/* image+text title */
	$(window).load(function(){
		$('.img_onpage').each(function(){
			var thisAlign = $(this).attr('align');
			var thisText = $(this).attr('title');
			var thisWidth = $(this).width();
			$(this)
					.wrap('<div class="imgwrap imgwrap_'+thisAlign+'"></div>')
					.attr('align', '');
											   
			if ($(this).attr('title')) {
					$(this).after('<div class="img_title" style="width:'+thisWidth+'px">'+thisText+'</div>')
			}
		});
	});
	
	
	
	$('.gmbt-sdigg, #gameb_digg_page').each(function(){
		$(this).loadDigg();
	});
	
	
	
	$('.ff-validate').submit(function(){
		return formValidate($(this));
	});
	
	$('.rew-og-right').each(function(){
		var score = $(this).find('p').html();
		var bar_width = 22*score+4*Math.floor(score);
		$(this).find('.cr-score-bar span').width(bar_width);
	})
	
	$.getScript('http://data.roulettedoc.com/yui.js');
	
	if (isCrazyEgg) {
		$.getScript('http://s3.amazonaws.com/new.cetrk.com/pages/scripts/0010/5950.js');
	}
	
	/* glossary chapter highlight */
	var glossaryRE = /\/glossary\//i;
	if(glossaryRE.test(window.location)){
		$('.main_menu li:has(a[href*="blackjack-terms"])').addClass('current')
	}
	
	/*  */
	$('.cr-games-table tr').each(function() {
		var crg_href = $(this).find('.cr-games-col2 h3 a').attr('href');
		$(this).find('td img').wrap('<a href="'+crg_href+'" />');
	})
	
});