var loadingGraphicPremiumFlash = '<div style="background-color: #000000; width: 615px; height: 345px;"><div class="loadingBar" style="color: #ffffff;padding-top:150px">Loading...<br /><img src="'+imgDir+'/common/loader_grey_bar.gif" /></div></div>'

function ajaxLoadHomePlayer(code, elToSwap) {
	
	var url = siteURL + '/homeplayerajax'

	jQuery.ajax({ url: url,
		data: {'action': 'load_player', 'code' : code, 'playerType' : 'premium'},
		type: 'post',
		success: function (responseText) {

			jQuery(elToSwap).html(responseText);

		}
	});

	jQuery(elToSwap).html(loadingGraphicPremiumFlash);

	trackClick(url + '/load_player/' + code);

}

function ajaxUnloadHomePlayer(code, elToSwap) {

	var url = siteURL + '/homeplayerajax'

	jQuery.ajax({ url: url,
		data: {'action': 'unload_player', 'code' : code, 'playerType' : 'premium'},
		type: 'post',
		success: function (responseText) {

			jQuery(elToSwap).html(responseText);

		}
	});

	jQuery(elToSwap).html(loadingGraphicPremiumFlash);

	//trackClick(url + '/unload_player/' + code);

}

function dimTheLights(mode){

	if(mode == 1){
		tb_dimmer(true);
		jQuery('#homePlayerFlashContainer').css('z-index',1004);
	}else if(mode == 0){
		tb_remove();
		jQuery('#homePlayerFlashContainer').css('z-index',99);
	}
	// this resolves issue of popup being over swf, swf being over thickbox, thickbox being over popup
	if(document.getElementById('inviteFriendPopup')){
		document.getElementById('inviteFriendPopup').style.display='none';
	}
}

function showWelcomeMessage(){

	var t = this.title || this.name || null;
	var a = siteURL+'/welcome?height=580&amp;width=670&amp;closer=no';
	var g = this.rel || false;
 	elToHide = new Array('player')
	tb_show(t,a,g, elToHide);

}

jQuery(window).load(function(){
	jQuery(window).data('isLoaded', true);
});
jQuery(document).ready(function(){
	jQuery('div.filmInfoBoxSmall').hover(function(){
		jQuery(this).css('background-image', 'url(' + imgDir + '/common/films/bg_film_infobox_small_89d749.png)');
	},function(){
		jQuery(this).css('background-image', 'url(' + imgDir + '/common/films/bg_film_infobox_small_ffffff.png)');
	});
	
	// make boxes clickable
	jQuery('#affiliatesPromo, #storyComposePromo2, #step-feel').click(function(){
		window.location = jQuery(this).find('a').get(0).href;
		return false;
	});


// deal with box bottom alignment
if (jQuery('#premFilmPromo').length == 1) { // free/nonmember state - add function to window load (after imgs have loaded)
	jQuery(document).bind('adjustBoxes', function(){
		var premBottom = jQuery('#premFilmPromo').offset().top + jQuery('#premFilmPromo').outerHeight();
		var nextstepsBottom = jQuery('#nextSteps').offset().top + jQuery('#nextSteps').height();
		var diff = nextstepsBottom - premBottom;
		if (diff > 0) {
			jQuery('#premFilmPromo').css('padding-bottom', parseInt(jQuery('#premFilmPromo').css('padding-bottom')) + diff + 'px');
		}
	});
	if (jQuery(window).data('isLoaded')) { // already loaded, trigger function
		jQuery(document).trigger('adjustBoxes');
	} else { // bind function to window load
		jQuery(window).load(function(){jQuery(document).trigger('adjustBoxes');});
	}
} else if (jQuery('#socialLinks').length == 1) { // premium state - bind a function to blog feed content loaded, also waits for window load
	jQuery(document).bind('adjustBoxes', function(){
		var socialBottom = jQuery('#socialLinks').offset().top + jQuery('#socialLinks').outerHeight();
		var nextstepsBottom = jQuery('#nextSteps').offset().top + jQuery('#nextSteps').height();
		var diff = nextstepsBottom - socialBottom;
		if (diff > 0) {
			jQuery('#socialLinks').css('padding-bottom', parseInt(jQuery('#socialLinks').css('padding-bottom')) + diff + 'px');
		}
	});
	jQuery('#blogfeed').bind('contentLoaded', function(){
		if (jQuery(window).data('isLoaded')) { // already loaded, trigger function
			jQuery(document).trigger('adjustBoxes');
		} else { // bind function to window load
			jQuery(window).load(function(){jQuery(document).trigger('adjustBoxes');});
		}
	});
}

});