﻿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);
	};
var promoInterval;
function promoClickChange(){
		if (this != window)
		{
			var sel = $(this)
			if (typeof promoInterval !='undefined') {clearInterval(promoInterval)}

		}
		else
		{
			if ($('.main-promo-selector-item.active').next('.main-promo-selector-item').children('a:first').length>0){var sel = $('.main-promo-selector-item.active').next('.main-promo-selector-item').children('a:first')}
			else {var sel = $('.main-promo-selector-item:first a:first-child');}

		}

		$('.main-promo-pic.active').fadeOut('slow').removeClass('active');
		$('.main-promo-selector-item.active').removeClass('active');
		sel.parent('.main-promo-selector-item').addClass('active');
		var sClass = sel.attr('class');

		sClass = sClass.replace(/main-promo-selector-(\S+$)/, "$1");
		$('.main-promo-'+sClass+'').fadeIn('slow').addClass('active');

};

function bonusClickOpen($this){

	if ($this.is('.crb-head-lock-opened')==true) {
		$this.parents('.cr-bonuses-content').removeClass('cr-bonuses-content-opened').find('.crb-inner-cont').hide();
		$this.removeClass('crb-head-lock-opened');
		$this.addClass('crb-head-lock-closed');
	} else if ($this.is('.crb-head-lock-closed')==true) {
		if (document.height<=800) {
			$('.crb-head-lock-opened').parents('.cr-bonuses-content').removeClass('cr-bonuses-content-opened').find('.crb-inner-cont').hide();
			$('.crb-head-lock-opened').removeClass('crb-head-lock-opened').addClass('crb-head-lock-closed');
			if ($this.parents('.cr-bonuses-content').prev().is('.cr-bonuses-content')) {
				$this.parents('.cr-bonuses-content').insertBefore('.cr-bonuses-content:first');
				var pos = $this.parents('.cr-bonuses-content').offset();
				window.scrollTo(0, pos.top);
			}
		}
		$this.parents('.cr-bonuses-content').addClass('cr-bonuses-content-opened').find('.crb-inner-cont').show();
		$this.removeClass('crb-head-lock-closed');
		$this.addClass('crb-head-lock-opened');
	}

}

$(document).ready(function() {
	/* Global */
	$('#nojs').attr('id', 'js');
	/* Opener */

	$('.open-options').each(function(){
		$(this).find('.opener').click(function(){
			$(this).parents('.open-options').find('.opened').slideToggle('fast', function(){
				if ($(this).parents('.review-info-payment').length>0) {
					$(this).siblings('.opener').remove();
				};
			});

		});

	});

	/* Universal Tabs */
	$('.univ-selector a').click(function(){
		$('.univ-selector td.active').removeClass('active');
		$('.univ-tab.active').removeClass('active');
		$(this).parent('td').addClass('active');
		var tabN = $(this).attr('name');
		$('.univ-tabs div[name*='+tabN+']').addClass('active');

	});

	/* OC Score Starboard */
	$('.crvs-stars').each(function(){
		var score = parseFloat($(this).parent('div').find('.crvs-cypher').text(), 10);
		var margin = 85-Math.round(score)*8.5;
		/*if ($(this).is('.crvs-stars-5') == true){
			margin = 85-Math.round(score*2)*8.5;
		};*/
		$(this).find('span').css('margin-right', margin);
	});


	$('a[href^=#]').click(function(){
		var ahash = $(this).attr('href');
		if (ahash.length>1) {
			if ($(ahash).length>0) {
				$('.target').removeClass('target');
				$(ahash).addClass('target');
			}
		};
	});

	/* Google Analytics goals */
	$('a[href^=visit/]').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]:not(a[href^=http://casino]):not(a[href^=http://onlinecasinosdoc]):not(a[href^=http://www.onlinecasinosdoc])').attr('target', '_blank');
	/* Main */
	$('.root').each(function(){
		/* Promo Tabs */
		promoInterval = setInterval(promoClickChange, 10000);
		$('.main-promo-selector-item a:first-child').hover(promoClickChange);
			$('.main-promo-selector-active').mouseenter(function() {
				if (typeof promoInterval !='undefined') {
					clearInterval(promoInterval)
				}
			}).mouseleave(function(){
				promoInterval = setInterval(promoClickChange, 10000)
			});

	});

	$('.inner-table-archtype').each(function(){
		$(this).find('tr:odd').addClass('odd');
		$(this).find('tbody tr:first').addClass('tr-first');
		$(this).find('tbody tr:last').addClass('tr-last');
		$(this).find('tr').each(function(){
			$(this).find('td:first').addClass('first');
		});
		$(this).find('tr').each(function(){
			$(this).find('td:last').addClass('last');
		});
	});

	$('.image-cont img').each(function(){
		$(this).load(function(){
			$(this).parents('.image-inner ').children('.image-txt').width($(this).width());
		});
	 });

	//$('.colorbox-screenshot').colorbox({transition:"elastic", opacity:"0.8"});

	$('.crb-head-lock').click(function(){
		bonusClickOpen($(this));

	});

	$('.crb-grpan-head, .crb-grpan-bonnuses-long').click(function(){
		bonusClickOpen($(this).siblings('.crb-head-lock'));

	});

	$('.crv-left').each(function(){
		$('.cr-bonuses-content:first').find('.crb-head-lock').each(function(){
			bonusClickOpen($(this));
		});
		bonushash = window.location.hash.substring(1);
		if ($('#bonus-'+bonushash).length>0) {
			$(this).find('.crb-head-lock-opened').each(function(){
				bonusClickOpen($(this));
			});
			$('#bonus-'+bonushash).find('.crb-head-lock').each(function(){
				bonusClickOpen($(this));
			});

		}
	});

	$('#cs_submit').click(function(e){
		e.preventDefault();

		$form = $(this).parents('form');
		var email_filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var formIsValid = true;

		$form.find('.input input').each(function(){

			if($(this).parents('.input').hasClass('required') && ($(this).val() == '')){
				$(this).addClass('error');
				formIsValid = false;
			}
			if($(this).is('#email') && (!email_filter.test($(this).val()))){
				$(this).addClass('error');
				formIsValid = false;
			}
			$('.error').focus(function(){
				$(this).removeClass('error');
			});
		})

		if(!formIsValid){
			return false;
		}

		$.post ('thanks-subscription.htm', $form.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>';
				}
				$form.parents('.fgbcs-inner, #side-subscribe-i').html(txt);
			}
		}, 'json');

		return false;
	});

});
