$(document).ready(function(){
	var subnav_title_width = $('#header .header_subnav li.section_title').width();
	var position = subnav_title_width+'px 0';
	$('#header .header_subnav').css('background-position',position);
})


function clearText(field){
 
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
 
}

$(document).ready(function(){
	$('#top_login_btn').click(function() {
	
	var btn_state = $('#top_login_btn').hasClass('active');
	
	if (btn_state == true) {
		$('#login_dropdown').animate({height:'0px'}, 100).hide();
		$(this).removeClass('active');
	} else {
		$('#login_dropdown').show().animate({height:'107px'}, 200);
		$(this).addClass('active');
	}
	
	  
	});
})

$(document).ready(function(){
	$('#instant_casino_catnav .item').click(function() {
		new_item =  $(this).index('#instant_casino_catnav .item');
		old_item =  $('#instant_casino_catnav .active').index('#instant_casino_catnav .item');
		new_div = '#casino_body_' + new_item;
		old_div = '#casino_body_' + old_item;
        
		
		if (new_item == old_item) {
			
		} else {
			$('#instant_casino_catnav .item.active').removeClass('active');
			$(old_div).stop().fadeOut(200);
			$(new_div).stop().fadeIn(200);
			$(this).addClass('active');
		}
	});
})

$(function() {
	$('#instant_casino_container .casino_cat_content .t3cat-link').click(function() {
	
		var n = $(this).hasClass('active');
		
		if (n == true) // if button being clicked is already active
		{
			$(this).removeClass('active');
			$(this).siblings('.play-btns').hide();
			$(this).siblings('.screenshot').hide();
		}
		else if (n == false) // if button being clicked isn't currently active
		{
			var cur_gc = $(this).siblings('.screenshot').children('.game_code').html();
			var screenshot_url = 'images/screenshots/gr88-game-'+cur_gc+'-320x240.jpg';
			$(this).siblings('.screenshot').children('img').attr('src',screenshot_url);
			$('#instant_casino_container .casino_cat_content .t3cat-link').removeClass('active');
			$('#instant_casino_container .casino_cat_content .t3cat-link').siblings().hide();
			$(this).addClass('active');
			$(this).siblings('.play-btns').stop().slideDown(150);
			$(this).siblings('.screenshot').stop().fadeIn(200);
		}
		
	})
})

// close screenshot with close btn
$(document).ready(function(){
	$('#instant_casino_container .screenshot #screenshot_close_btn').click(function() {
		$(this).parent('.screenshot').siblings('.t3-cat-link').removeClass('active');
		$(this).parent('.screenshot').siblings('.play-btns').hide();
		$(this).parent('.screenshot').stop().hide();
	})
})

$(document).ready(function(){
	$('#signup-step .game-box .box').toggle(function() {
		$(this).siblings('.dl-dropdown').stop().animate({marginTop:'-86px'}, 200);
	}, function() {
		$(this).siblings('.dl-dropdown').stop().animate({marginTop:'-167px'}, 200);
	});
})

function openCasino() {
	casinoWindow=window.open('http://www.gr88.com/en/casino/index.php?action=launch&mode=real','','width=860,height=700,location=no,menubar=no,location=no,status=no,toolbar=no,scrollbars=yes,resizable=yes');
	casinoWindow.focus();
}

function openGame(id, type) {
    var launchURL = type == 1 ? 'instant-play.php?action=launch&mode=real&id=' + id : 'instant-play.php?action=launch&mode=fun&id=' + id
    var w = 860, h = 600
    gameLauncherWindow = window.open(launchURL, 'xc_launcher', 'width=' + w + ', height=' + h + ', location=no, menubar=no, location=no, status=no, toolbar=no, scrollbars=yes, resizable=yes')
    if(gameLauncherWindow) gameLauncherWindow.focus()
}

$(document).ready(function(){
	$('a').click(function() {
		if ($(this).attr('rel')=='play_for_real' || $(this).attr('rel')=='play_for_fun') {
			openGame(
				$(this).attr('href').substr(1),
				$(this).attr('rel') == 'play_for_real' ? 1 : 0
			)
			return false
		}
		else {
		}
	})
})

$(document).ready(function(){
	$('.faq_box .faq_q .q_title').toggle(function() {
		$(this).parent('.faq_q').addClass('active');
		$(this).siblings('.faq_a').stop().slideDown(100);
	}, function() {
		$(this).parent('.faq_q').removeClass('active');
		$(this).siblings('.faq_a').stop().slideUp(100);
	});
})

$(document).ready(function(){
	$('#content_sidebar .item.title span').click(function() {
		if ($(this).parent('.item.title').hasClass('active') == true) {
			$(this).parent('.item.title').removeClass('active');
			$(this).siblings('.content_sidebar_dropdown').stop().slideUp(120);
		} else {
			$(this).parent('.item.title').addClass('active');
			$(this).siblings('.content_sidebar_dropdown').stop().slideDown(120);
		}
	})
})

$(document).ready(function(){
	$('#terms .btn').click(function() {
	
	var btn_state = $(this).parent('#terms').hasClass('active');
	
	if (btn_state == true) {
		$(this).siblings('.inner').stop().slideUp(150);
		$(this).parent('#terms').removeClass('active');
		$(this).html('Show Terms &amp; Conditions');
	} else {
		$(this).siblings('.inner').stop().slideDown(150);
		$(this).parent('#terms').addClass('active');
		$(this).html('Hide Terms &amp; Conditions');
	}
	});
})

// detect body id, enable correct subnav in header iframe
function setSubNav() {
	var curSec = $('body').attr('id');
	if (curSec == 'casino') {
		$('#em_header').contents().find('#menuRootGroup .menuItem.casino .menuSubHorizontal').show();
	} else if (curSec == 'poker') {
		$('#em_header').contents().find('#menuRootGroup .menuItem.casino .menuSubHorizontal').show();
	} else if (curSec == 'bingo') {
		$('#em_header').contents().find('#menuRootGroup .menuItem.bingo .menuSubHorizontal').show();
	} else if (curSec == 'sports') {
		$('#em_header').contents().find('#menuRootGroup .menuItem.sports .menuSubHorizontal').show();
	} else {
		$('#em_header').contents().find('#menuRootGroup .menuItem.default .menuSubHorizontal').show();
	}
}
