var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";

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 raffleClose()	{
	$('#rf-cont').hide();
	$('#lb-overlay').hide();
	
}
function pasteWarning(input) {
	$(input).siblings('label').find('.rf-error').remove();
	var err = $('<div/>').addClass('rf-error').text('Paste disallowed');
	$(input).siblings('label').append(err);
}
function raffle() {
	var ft = 1;
	var fn = location.href.substring(location.href.lastIndexOf('/')+1) ;
	fn = fn.substring(0, fn.length-4);
	if (Math.floor(Math.random()*101)>=50) {
		$('#rf-cont').attr('class', 'rf-awk');
		ft = 2;
	}
	$('#rf-cont').show();
	$('#lb-overlay').show();
	$('#rf-name').focus();
	$('.rff-item input').keyup(function(e){
		if (e.keyCode == '13' ||e.keyCode == '10' ) {
		     e.preventDefault();
		     $('#rf-first-button').addClass('rf-keyup').trigger('click');
		}
	});
	$('#rf-cont, #rf-close, #rf-back').click(function(z){
		z.preventDefault();
		raffleClose();
	})
	$('#rf-actual').click(function(z){
		z.stopPropagation();
	});
	trackPageview('raffle-view/'+fn+'/form:'+ft);
}
function makeEqualHeight(a, b) {
	var ah = $(a).height();
	var bh = $(b).height();
	var hmax = Math.max(ah, bh);
	$(a).height(hmax);
	$(b).height(hmax);
};

function formError($this, errMsg) {
	var $error = $('<span/>').addClass('lb-error').text(errMsg);
	$this.find('input').css('background-position', '0 -31px');
	$this.append($error);
};

function makeSnippet($this, type, errtext) {
	var $snipp = $this;
	if (type == 'error') {
		$snipp = $this.parents('td').siblings('td:last').find('.lbr-help');
		if ($snipp.length==0) {
				$this.parents('td').siblings('td:last').append('<span class="lbr-help lbr-error-add" id="lbr'+$this.attr('name')+'"></span>');
				$snipp = $this.parents('td').siblings('td:last').find('.lbr-help');
			}
	}
	var pos = $snipp.position();
	pos.left = pos.left+29;
	var snippText = $snipp.find('span').html();
	var snippId = $snipp.parents('td').siblings('.lbr-input').find('input').attr('id');
	var $snippet = $('<span/>').addClass('lbr-snippet').css({'top':pos.top+'px', 'left':pos.left+'px'}).attr('id', 'lbrs'+snippId);
	if (errtext===undefined || errtext=='') {
		errtext = snippText;
	}
	if (type == 'help') {
		$snipp.css({'background-position':'0 -22px'});
		$snippet.html(snippText);
	} else if (type == 'error') {
		$snipp.addClass('lbr-error').css({'background-position':'0 -44px'});
		$snippet.addClass('lbr-error-add').css('border-color', '#cc0000').html(errtext);
	} else if (type == 'remove') {
		$('#lbrs'+snippId).remove();
		$snipp.css({'background-position':'0 0'});
		return false;
	}
	$('#registration, #change_registration').append($snippet);
};

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() == '') {
				validate = false;
				v = -1;
			}
			if ($thisForm.is('.gmbt-fform') && $(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;
}
var is_logged = false;
$(document).ready(function(){
	/* JS - NOJS */

	$('.container').attr("id", 'js');
	
	/* cunning image links */
	$('.pic-lnk').click(function(){
		//location.href = $(this).attr('rel');
		window.open($(this).attr('rel'),'_blank');
	})
	
	makeEqualHeight('.sc_rev_jackpot', '.sc_rev_pcw_jackpot');
	
	/* colorbox + slots review button in lightbox */
	$('.colorbox-screenshot').each(function(){
		$(this).colorbox({transition:"elastic", opacity:"0.8"}, function(){
			if ($(this).parents('.sc_rev_screenbox')) {
				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.shown').remove();
				}); 
			}
		});
	});
	$(".ff-validate").submit(function() {
	    return formValidate($(this))
	  });
	/* 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');
	});
	
	/* dirty tricks */
	var lwH = $('.leftwrapper').height();
	var rwH = $('.right').height();
	if (lwH < rwH) $('.leftwrapper').css('min-height', rwH);
	
	$('.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-22);
		$(this).width(tableW+19);
	})
	
	/* FAQ slidedown */
	$('.faq dd').hide();
	$('.faq dt a').click(function(ev){
		ev.preventDefault();
		$(this).parent('dt').next('dd').slideToggle('fast');
	});
	
	/* press tabs */
	$('.press_tab').click(function(){
	if ($(this).hasClass('active') == true)
		{}
		else
		{$('.press_tab, .press_head .seeall, .press_wrap').toggleClass('active');}
	});

	/* SC List Tabs */
	$('.sc_list_selector a').click(function(){
		var sc_list_cl = $(this).attr('name');
		$('.sc_list_selector .active').removeClass('active');
		$('.sc_list_cont.active').removeClass('active');
		$(this).addClass('active');
		$('.sc_list_cont.'+sc_list_cl+'').addClass('active');
		
		
	});
	
	$('.sc_list_selector').each(function(){
		if(location.hash){
			var sc_list_cl = 'sc_list_'+location.hash.substring(1)+'';
			$('.sc_list_selector .active').removeClass('active');
			$('.sc_list_cont.active').removeClass('active');
			$('.sc_list_selector a[name*='+sc_list_cl+']').addClass('active');
			$('.sc_list_cont.'+sc_list_cl+'').addClass('active');	
		}								 
	});
	
	$('.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();
		}
	});
	
	/* poll deviation 
	$('.box_poll .poll_form ol').addClass('poll_divide1').after('<ol class="poll_divide2"></ol>');
	var pollItems = $('.box_poll .poll_form li').length;
	var x1 = Math.ceil(pollItems/2);
	$('.box_poll .poll_form li:gt('+(x1-1)+')').appendTo('.poll_divide2');
	*/
	
	
	/*$('li a[href*="free-slots"]').parent('li').addClass('hotpage');
	$('li a[href*="tournaments-schedule"]').parent('li').addClass('newpage');
	$('li a[href*="how-to-win-at-slots"]').parent('li').addClass('updpage');
	$('li a[href*="slots-finder"]').parent('li').addClass('toolpage');*/
	
	/* new */
	var $main_menu_lis = $('.main_menu li');
	$main_menu_lis.find('a[href$="high-scores.htm"]').parent('span').addClass('mm-icon newpage');
	/* hot */
	$main_menu_lis.find('a[href*="slot-games.htm"], a[href$="all-slots.htm"], a[href$="new-online-slots.htm"]').parent('span').addClass('mm-icon hotpage');
	/* tool */
	$main_menu_lis.find('a[href$="slots-finder.htm"]').parent('span').addClass('mm-icon toolpage');
	/* upd */
	/* $('.main_menu li a[href$="tournaments.htm"], .main_menu li a[href$="progressive-slot-machines.htm"]').parent('span').addClass('mm-icon updpage'); */
	
	/* Google Analytics goals */
	$('a[href^=play/]').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]:not(a[href^=http://casino]):not(a[href^=http://slotsdoc]):not(a[href^=http://www.slotsdoc])').attr('target', '_blank');
	$('a:not(.sc_partlink)[href^=play/]').attr('target', '_blank');
	
	
	$('.gameb_feedback_form').submit(function(e){
		e.preventDefault();
		var $thisForm = $(this);
		var gfName = $thisForm.find('.gameb_feedback_name').val();
		var gfEmail = $thisForm.find('.gameb_feedback_email').val();
		var gfText = $thisForm.find('textarea').val();
		var gfSubj = $thisForm.find('input[name=subject]').val();
		if(!gfText || gfText==$thisForm.find('textarea').get(0).defaultValue) {
			$thisForm.find('textarea').each(function(){
				if ( $(this).val()==$(this).get(0).defaultValue || $(this).val()=='' )
				{$(this).css('border-color', 'red')}
			});
			e.preventDefault();
			return false;
		}
	
		$.post('thanks-feedback.htm', {
			name: gfName,
			email: gfEmail,
			content: gfText,
			subject: gfSubj
		}, function(){
			if (!gfName || gfName==$thisForm.find('.gameb_feedback_name').get(0).defaultValue)
			{gfName = 'visitor'}
			var txt = '<h2>Thank you!</h2><p>Dear ';
			txt+=gfName;
			txt+=', thank you for your feedback! We appreciate your help and will take into account your suggestions and comments in future.</p>';
			$('.bb3_body').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).is('#email') && (!email_filter.test($(this).val()))) ||
				($(this).is('#email') && $(this).val()=='')
			){
				$(this).parents('.input').append('<div class="error">You should type a valid email</div>')
				formIsValid = false;
			}
		})
		
		if(!formIsValid){
			return false;
		}
		
		$.post ('thanks-subscription.htm', $(this).serialize(), function(data,status){
			if(status=='success'){
				data = eval(data.substring(1));
				var txt;
				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><br>To complete the subscription process, please click the link in the email we just sent you.</p>';
				}
				$('.newsletter_form').html(txt);
			}
		}/*, 'json'*/);
		
		return false;
	});
	
	/* form focus */
	$('.gameb_feedback_form textarea, .gameb_feedback_form input[type=text]').focus( function(){
		if (this.defaultValue == $(this).val())
			{$(this).css('color', '#333').val('').css('border-color', '');}
	});
	$('.gameb_feedback_form textarea, .gameb_feedback_form input[type=text]').blur( function(){
		if ($(this).val() == '')
			  {$(this).css('color', '#999').val(this.defaultValue);}
	});
	
	
	$('.sc_sortable_cloud').each(function(){
		var kFilename = location.href.split('/');								  
		var jFilename = kFilename[kFilename.length-1];
		
		$(this).find('a[href*='+jFilename+']').addClass('current');
	});
	
	
	
	/*$('.gameb_digg, #gameb_digg_page').each(function(){
		$(this).loadDigg();
	});*/
	
	
	$(".sc_sortable table, .tournaments_schedule").each(function(){
		if ($(this).is('.sc_sortable table')) {
			$(this).tablesorter({
				cssHeader:'sorthead',
				cssAsc:'sorthead_up',
				cssDesc:'sorthead_down',
				sortList:[[0,0]],
				headers: {5: { sorter: false}, 6: {sorter: false} },
				textExtraction: 'complex'
				});
			$("th.c4, th.c5, th.c6").toggle(
				function() {
					if ($(this).hasClass('c4')) {var sorting = [[2,1]];}
					if ($(this).hasClass('c5')) {var sorting = [[3,1]];}
					if ($(this).hasClass('c6')) {var sorting = [[4,1]];}
					$("table").trigger("sorton",[sorting]); 
					return false; 
				},
				function() { 
					if ($(this).hasClass('c4')) {var sorting = [[2,0]];}
					if ($(this).hasClass('c5')) {var sorting = [[3,0]];}
					if ($(this).hasClass('c6')) {var sorting = [[4,0]];}
					$("table").trigger("sorton",[sorting]); 
					return false; 
				});
			};
			
		if ($(this).is('.tournaments_schedule')) {
			$(this).tablesorter({
				cssHeader:'sorthead',
				cssAsc:'sorthead_up',
				cssDesc:'sorthead_down',
				sortList:[[0,0]],
				headers: {6: {sorter: false} },
				textExtraction: 'complex'
				});
			$(".tournaments_schedule th.tns-prize").toggle(
				function() {
					if ($(this).hasClass('tns-prize')) {var sorting = [[4,1]];}
					$(".tournaments_schedule").trigger("sorton",[sorting]); 
					return false; 
				},
				function() { 
					if ($(this).hasClass('tns-prize')) {var sorting = [[4,0]];}
					$(".tournaments_schedule").trigger("sorton",[sorting]); 
					return false; 
				});
			};
	}); 
	$(".sc_sortable table").each(function(){
		$(this).parents('.sc_sortable:last-child').css('padding-bottom', '20px');
		
		$(this).find('.sc_piclink').each(function(e){
			$(this)
			.mouseenter(function(){
				var pic_uid = $(this).attr('rel');
				$(this).find('.scp_b')
					.css('background-image', 'url(img/slots-catalog/screens/review-thumbnail/'+pic_uid+'-1.jpg)');
				$(this).children('.scp_c')
					.css('visibility','hidden')
					.clone()
					.appendTo('body')
					.addClass('sc_sortable_lostspan')
					.css({'z-index':'100', 'visibility':'visible'});
				$(this).mousemove(function(d){
					$('.sc_sortable_lostspan').css({'top':''+(d.pageY+10)+'px', 'left':''+(d.pageX+10)+'px'})
				});
			})
			.mouseleave(function(){
				$('.sc_sortable_lostspan').remove();
			})
		});
	
	});
	
	$('.tns-name a').hover(function(e){
		$(this).siblings('.tns-name-appendix')
			.clone()
			.appendTo('body')
			.addClass('tns-name-appended')
			.show()
			.css({'top':''+(e.pageY+10)+'px', 'left':''+(e.pageX+10)+'px'})
			
	},
		function(){
			$('.tns-name-appended').remove();
		});
	
	$('.tns-game a').hover(function(e){
		var game_uid = $(this).attr('href').substring(0, $(this).attr('href').length-17);
		$('body').append('<div class="tns-game-appendix"><div style="background:url(img/slots-catalog/screens/review-thumbnail/'+game_uid+'-1.jpg) 0 0 no-repeat;"></div></div>');
		$('.tns-game-appendix').css({'left':''+(e.pageX+10)+'px', 'top':''+(e.pageY+10)+'px'});
		$(this).mousemove(function(d) {
			$('.tns-game-appendix').css({'left':''+(d.pageX+10)+'px', 'top':''+(d.pageY+10)+'px'});
		});
	}, function(){
			$('.tns-game-appendix').remove();
	});
	
	
	$('.tournaments_schedule').parents('body').mousemove(function(e){
		if ($(e.target).is('.tns-addevent')) {
			var $this = $(e.target);
			var h = $this.offset();
			if (!$('.tns-addevent-appended').is('.taa-'+h.top+'')) {
				$('.tns-addevent-appended').remove();
			};
			$this.find('.tns-addevent-appendix')
					.clone()
					.addClass('tns-addevent-appended')
					.addClass('taa-'+h.top+'')
					.appendTo('body')
					.show()
					.css({'left':''+h.left+'px', 'top':''+(h.top+30)+'px'});
			
		};
		if  (!$(e.target).is('.tns-addevent') && !$(e.target).is('.tns-addevent-appendix, .tns-addevent-appendix *')) {
			$('.tns-addevent-appended').remove();
		};
	});
	
	if (isCrazyEgg) {
		$.getScript('http://s3.amazonaws.com/new.cetrk.com/pages/scripts/0010/5950.js');
	};
	/*  */
	$('.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+'" />');
	})
	
	$('.gmbts-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('.gmbtsf-input input').each(function(){
			$(this).parents('.gmbtsf-input').find('.error').remove();
			
			if($(this).parents('.gmbtsf-input').hasClass('required') && ($(this).val() == '')){
				$(this).parents('.gmbtsf-input').append('<div class="error">This field is required</div>')
				formIsValid = false;
			}
			if($(this).parents('.gmbtsf-input').hasClass('email') && (!email_filter.test($(this).val()))){
				$(this).parents('.gmbtsf-input').append('<div class="error">You should type a valid email</div>')
				formIsValid = false;
			}
		})
		
		if(!formIsValid){
			return false;
		}
		
		$.post ('thanks-subscription.htm', $(this).serialize(), function(data,status){
			if(status=='success'){
				data = eval(data.substring(1));
				var txt;
				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><br>To complete the subscription process, please click the link in the email we just sent you.</p>';
				}
				$('.gmbts-form').html(txt);
			}
		}/*, 'json'*/);
		
		return false;
	})
	
	$('#sign-in').click(function(e){
		e.preventDefault();
		if ($('body').is('.game_small')) {
			hideFlash();
			if (!flag) {
				window.location='login.htm';
				return false;
			}
		};
		$('#lb-overlay').show();
		$('#lb-bodycont').fadeIn('slow');
	});
	$('#lblb-close, #lb-bodycont, #lblbbb-askme').click(function(e){
		e.preventDefault();
		if ($('body').is('.game_small')) {
			showFlash();
		};
		$('#lb-overlay').hide();
		$('#lb-bodycont').fadeOut('fast');
	});
	$('#lb-lightbox').click(function(e){
		e.stopPropagation();
	});
	$('#lblb-submit').click(function(e){
		e.preventDefault();
		var $form = $(this).parents('form');
		var formIsValid = true;
		var errMsg = '';
		$('.lb-error').remove();
		$form.find('.lblb-input input').each(function(){
			$(this).css('background-position', '0 0');
			if ($(this).val().length==0) {
				formIsValid = false;
				formError($(this).parents('.lblb-input'), 'Required field');
			};
		});
		if (!formIsValid) {
			return false;
		}
		$form_serialized = $form.serialize()+'&ajax=1';
		$.post ('login-ajax.htm', $form_serialized, function(data){
			if (data.status=='ok') {
				if (!$('body').is('#logout') && !$('body').is('#login')){
					
					window.location.reload();
				} else {
					
					window.location = 'free-slots.htm';
				};
			} else {
				if (data.errors) {
					for (i in data.errors) {
						if (i=='wrong_login') {
							formError($('input[name=username]').parents('.lblb-input'), 'Wrong login');
						}
						if (i=='wrong_password') {
							formError($('input[name=password]').parents('.lblb-input'), 'Wrong password');
						}
					}
				}
			}
		}, 'json');
	});
	$('.lblb-input input, .lbr-input input').keyup(function(e){
		if (e.keyCode == '13' ||e.keyCode == '10' ) {
		     e.preventDefault();
		     $('#lblb-submit, #lbr_submit').trigger('click');
		}
	});
	$('.lbr-help').toggle(function(){
		if ($(this).not('.lbr-error').length!=0) {
			makeSnippet($(this), 'remove');
			makeSnippet($(this), 'help');
		}
	}, function(){
		if ($(this).not('.lbr-error').length!=0) {
			makeSnippet($(this), 'remove');
		}
	});
	
	$('#lbr_submit').click(function(e){
		e.preventDefault();
		var $form = $(this).parents('form');
		var $result = $form.serializeArray();
		var psswr = '';
		var action = $form.attr('action');
		var isValid = true;
		$form.find('.lbr-help').each(function(){
			makeSnippet($(this), 'remove');
		});
		$('.lbr-error-add').remove();
		$('.lbr-error').removeClass('lbr-error');
		
		for (var i=$result.length-1; i>=0; i--) {
			var isError = false;
			var isBender = false;
			var errMsg = '';
			var email_filter = /^([a-zA-Z0-9_\.\-\+\$\!\#])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var common_filter = /^[a-zA-Z0-9_]+$/;
			var common_name_filter = /^[a-zA-Z0-9_\. ]+$/;
			if ($form.is('#registration')) {
				if ($result[i].value=='Year' && $result[i].name=='birthday-year') {
					isError = true;
					errMsg = 'Please specify your birth year.';
				}
				if ($result[i].value.length==0 && $result[i].name!='name' && $result[i].name!='country') {
					isError = true;
					errMsg = 'This field is required.';
				}
				if ($result[i].name=='country' && $result[i].value!='') {
					isBender = true;
					errMsg = 'Automated registration attempt detected. If you are human, try to reload the page. If you still recieve this error, please <a href="contacts.htm">contact us</a> to resolve your problem.';
				}
				if (isError !== true) {
					if ($result[i].value!=''){
						if ($result[i].name=='username' || $result[i].name=='password') {
							if (!common_filter.test($result[i].value)) {
								isError = true;
								errMsg = 'Allowed characters: <strong>a-z, A-Z, 0-9, _</strong>';
							}
							if ($result[i].value.length<3) {
								isError = true;
								errMsg = 'Minimum 3 characters is allowed';
							}
						}
						if ($result[i].name=='name') {
							if (!common_name_filter.test($result[i].value)) {
								isError = true;
								errMsg = 'Allowed characters: <strong>a-z, A-Z, 0-9, _, . and space</strong>';
							}
							if ($result[i].value.length<3) {
								isError = true;
								errMsg = 'Minimum 3 characters is allowed';
							}
						}
					}
				}
				if (isError !== true) {
					if ($result[i].name=='password_r') {
						psswr = $result[i].value;
					}
					if ($result[i].name=='password') {
						if ($result[i].value!=psswr) {
							isError = true;
							errMsg = 'Passwords do not match';
						}
					}
				}
				if (isError !== true) {
					if ($result[i].name=='email') {
						if (!email_filter.test($result[i].value)) {
							isError = true;
							errMsg = 'Wrong email';
						}
					}
				}
			} else if ($form.is('#change_registration')) {
				
				if ($result[i].name=='password' || $result[i].name=='password_r' || $result[i].name=='password_current') {
					if ($result[i].value=='') {
						$form.find('input[name='+$result[i].name+']').addClass('lbr-excluded');
					}
				}
				if ($result[i].value!=''){
					if ($result[i].name=='password') {
						if (!common_filter.test($result[i].value)) {
							isError = true;
							errMsg = 'Allowed characters: <strong>a-z, A-Z, 0-9, _</strong>';
						}
						if ($result[i].value.length<3) {
							isError = true;
							errMsg = 'Minimum 3 characters is allowed';
						}
					}
					if ($result[i].name=='name') {
						if (!common_name_filter.test($result[i].value)) {
							isError = true;
							errMsg = 'Allowed characters: <strong>a-z, A-Z, 0-9, _, . and space</strong>';
						}
						if ($result[i].value.length<3) {
							isError = true;
							errMsg = 'Minimum 3 characters is allowed';
						}
					}
				}
				if (isError !== true) {
					if ($result[i].name=='password_r') {
						psswr = $result[i].value;
					}
					if ($result[i].name=='password') {
						if ($result[i].value!=psswr) {
							isError = true;
							errMsg = 'Passwords do not match';
						}
					}
				}
				
			}
			if (isError === true){
				makeSnippet($form.find('*[name='+$result[i].name+']'), 'error', errMsg);
				isValid = false;
			}
			if (isBender === true){
				makeSnippet($form.find('input[name=username]'), 'error', errMsg);
				isValid = false;
			}
		}
		var $form_serialized = $('#'+$form.attr('id')+' :input[value]').serialize();
		
		if (isValid) {
			$('#lbr_submit span').text('');
			$('#lbr_submit').attr('id', 'lbr_submit_disabled');
			$.post (action, $form_serialized, function(data,status){
				if(data.status=='ok'){
					window.location='profile.htm';
				} else {
					$('#lbr_submit_disabled').attr('id', 'lbr_submit');
					for (i in data.errors) {
						makeSnippet($form.find('input[name='+i+']'), 'error', data.errors[i]);
					};
				}
			}, 'json');
		}
		
	});
	
	$('.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');
			}
			$lbp = /^#lb-.+/;
			if ($lbp.test($(this).attr('href'))) {
				window.location.hash = $(this).attr('href').substring(4);
				HSmakeLink();
			}
		})
	});
	
	function HSmakeLink() {
			var actv = $('#scores-tabs').find('.active');
			var lbb_link = $('<a/>').attr('href', actv.attr('rel')).text('Play '+actv.text()+' Slots');
			var lbb_link_p = $('<p/>').attr('id', 'lbb-link').append(lbb_link);
			$('#lbb-link').remove();
			$('#scores-tables').after(lbb_link_p);
		}
	$('#high-scores').each(function(){
		
		if (window.location.hash.length > 0) {
			var hash = window.location.hash.substring(1);
			$('.cmn_tabs').find('a[href=#lb-'+hash+']').trigger('click');			
		}
		
		HSmakeLink();
	});
	$('#change-password').click(function(e){
		e.preventDefault();
		$(this).parents('tr').remove();
		$('.changep-row').each(function(){
			$(this).attr('class', 'changep-row-shown');
			$(this).find('input').removeAttr('disabled');
		});

	});
	$('.game_small').each(function(){
		var games_hashes = {
			'play-blackjack':'classicbj',
			'vegas-strip':'vegas',
			'progressive-blackjack-game':'progressive',
			'perfect-pairs-game':'perfectpairs',
			'blackjack-switch':'switch',
			'superfun-21':'superfun',
			'pontoon-game':'pontoon'
		};
		var fn = $(this).attr('id').substring(5);
		for (i in games_hashes) {
			if (fn == i) {
				$('.main_menu a[href=high-scores.htm]').attr('href', 'high-scores.htm#'+games_hashes[i]+'');
			}
		};
	});
	$('#pass-recovery').submit(function(){
		return formValidate($(this));
	});
	/* */
	$('#tn-close').click(function(){
		$(this).parents('#index_topnotch').slideUp('slow');
	})
	$('.ixpt-us').mouseenter(function(e){
		var usPos = $(this).position();
		$('#us-ttip').css({'left':usPos.left+6+'px', 'top':usPos.top-30+'px', 'display':'block'});
	});
	$('.ixpt-us').mouseleave(function(e){
		$('#us-ttip').hide();
	});
	
	$('#index_topnotch').each(function(){
		var $this = $(this);
		if (!FlashDetect.installed) {
			makeBonusImage();
		} 
		function makeBonusImage() {
			$this.html('');
			var bonus_img = $this.attr('rel').split(',');
			$this
				.append($('<a/>').attr('href', bonus_img[1]).attr('rel', '_nofollow').attr('target', '_blank')
					.append($('<img/>').attr('src', bonus_img[0]).attr('width', $this.width()).attr('height', $this.height()))
				)
				.append($('<span/>').attr('id', 'tn-close'));
			$this.find('#tn-close').click(function(){
				$this.slideUp('slow');
			});
		}
		
	})
	if ($('body').is('#free-slots')) {
		if (!$.cookie('raffle') && !$.cookie('raffle_permanent')) {
			raffle();
			$.cookie('raffle', 'onload', { expires: 30 });
		}
	};
	
	function sendRaffle(e){
		var form_location = 'default';
		if ($(this).parents('#rf-cont').length>0) {
			var $form = $('#rf-form');
		} else if ($(this).parents('#ix-raffle').length>0) {
			var $form = $('#rfm-form');
			form_location = 'main';
		} else if ($(this).parents('#side-raffle').length>0) {
			var $form = $('#rfs-form');
			form_location = 'sidebar';
		}
		if ($(this).is('.rf-wait-state')) {
			return false;
		}
		e.preventDefault();
		$('.rf-error').remove();
		var button_type = '1';
		var form_type = '1';
		$('.rf-button').addClass('rf-wait-state');
		if ($(this).is('#rf-first-button')) {
			$form.find('input[name="button"]').val('1');
		}
		if ($(this).is('#rf-second-button')) {
			$form.find('input[name="button"]').val('2');
			button_type = '2';
		}
		if ($(this).is('.rf-keyup')) {
			$form.find('input[name="button"]').val('3');
			button_type = '3';
		}
		if ($(this).parents('#rf-cont').is('.rf-awk')) {
			$form.find('input[name="form"]').val('2');
			form_type = '2';
		}
		var email_filter = /^([a-zA-Z0-9_\.\-\+\$\!\#])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var name_filter = /^[a-zA-Z0-9_\. ]+$/;
		var isValid = true;
		var action = $form.attr('action');
		var $result = $form.serializeArray();
		for (var i=$result.length-1; i>=0; i--) {
			var isError = false;
			var errMsg = '';
			if ($result[i].value.length==0) {
				isError = true;
				if (form_location=='default') {
					errMsg = 'Required field';
				} else {
					errMsg = 'Required';
				}
			}
			if (!isError) {
				if ($result[i].name=='name') {
					if (!name_filter.test($result[i].value)) {
						isError = true;
						errMsg = 'Wrong name';
					}
				}
			}
			if (!isError) {
				if ($result[i].name=='email') {
					if (!email_filter.test($result[i].value)) {
						isError = true;
						errMsg = 'Wrong email';
					}
				}
			}
			if (!isError) {
				if ($result[i].name=='rf-email-c' || $result[i].name=='email-c') {
					var email_c = $result[i].value;
				}
				if ($result[i].name=='email') {
					if (email_c != $result[i].value) {
						isError = true;
						errMsg = 'E-mails do not match';
					}
				}
			}
			if (isError) {
				var err = $('<div/>').addClass('rf-error').text(errMsg);
				$form.find('label[for="'+$result[i].name+'"]').append(err);
				isValid = false;
				$('.rf-button').removeClass('rf-wait-state');
			}
		}
		if (isValid) {
			$form = $form.serialize();
			$.post (action, $form, function(data,status){
				if(data==='ok'){
					$('.rf-button').removeClass('rf-wait-state');
					if (form_location=='default') {
						$.cookie('raffle_permanent', 'permanent', { expires: 365 });
						trackPageview('raffle-submit/form:'+form_type+'/button:'+button_type);
						$('#rf-cont').attr('class', 'rf-normal').addClass('rf-thank-state');
					} else {
						trackPageview('raffle-submit/'+form_location);
						$('#rfg-actual').hide();
						$('#rfg-thanks').show();
					}
				} else {
					$('.rf-button').removeClass('rf-wait-state');
					alert(data);
				}
			}, 'text');
		}
		
	}
	
	$('.rf-button').click(sendRaffle);

	$('input[type="text"]','#rfs-form').keyup(function(e){
		if(e.keyCode == 13 || e.keyCode == 10) sendRaffle.call($('.rf-button'),e);
	});
});
$(window).load(function(){
	/* branding */
//	$("#partner_top").each(function(){
//		
//		rt = 'http://slotsdoc.com/';
//		var pt = $(this).attr("rel");
//		var brand_img = $("<img/>").attr("src", rt+"img/branding/"+pt+"-top.gif").load(function(){
//			$("#partner_top").find("a").attr('target', '_blank').append(brand_img);
//			$("div#side-bonus").each(function(){
//				var pt_2 = $(this).attr("rel");
//				var brand_img_2 = $("<img/>").attr("src", rt+"img/branding/"+pt_2+"-side.gif")
//				$("div#side-bonus").find("a").attr('target', '_blank').append(brand_img_2);
//			});
//		});
//		if ($('body').attr('id')!='page_404') {
//			$("body").css("background-image", "url("+rt+"img/branding/"+pt+"-bg.jpg)").addClass("brand-"+pt);
//		}
//	});
	var lwH = $(".leftwrapper").height();
	var rwH = $(".right").height();
	if(lwH < rwH) {
		$(".leftwrapper").height(rwH)
	}
});
window.fbAsyncInit = function() {
	function applyHeight() {
		$('.sc_cont').height($('.sc_fblike').height());
	}
	FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
	FB.Event.subscribe('xfbml.render', function(response) {
		var t = setTimeout(function(){
		 	applyHeight();
		 	//$('.social_common').clone().insertAfter('h1');
		}, 1500);
		
	});
	FB.Event.subscribe('edge.create', function(response) {
		applyHeight();
	});
	FB.Event.subscribe('edge.remove', function(response) {
		applyHeight();
	});
	
};
