(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  };
})(jQuery);


$(document).ready(function(){
	$('input[type=text], input[type=password], textarea').each(function(i){
	    $(this).focus(function(){
	       $(this).addClass('inputSelected');
	    }).blur(function(){
	       if ($(this).hasClass('inputSelected')) {
	          $(this).removeClass("inputSelected");
	       }
	    });
	 });
	
	
	$('a.fancy').fancybox({
		titlePosition: 'inside'
	});
	
});

var videoLoading = false;

function playVideoLightbox(flashvars, params, attributes, width, height) 
{
	if (videoLoading == true) return;
	videoLoading = true;
	if (!width)  width  = 520;
	if (!height) height = 436; // +46
	
	var relatedSize = 350;	
	var boxy = new Boxy("<div id=\"vid" + flashvars.id + "Related\" class=\"boxyVideos\"></div><div id=\"vid" + flashvars.id + "\" class=\"boxyVideo\"><div id=\"vid" + flashvars.id + "Video\"></div></div><div id=\"vidComments\" class=\"videoComments\"></div>", {title: flashvars.title, modal: true, center: true, fixed: false, show: false, unloadOnHide: true});
	$('.boxy-inner').attr('class', 'boxy-innerVideo');
	if (!params) {
		var params = {
		          'allowFullScreen':    'true',
		          'allowScriptAccess':  'always',
		          'bgcolor':            '#62636B',
		          'quality':            'best',
		          'scale':              'noscale'
		       };		       		
	}
	if (!attributes) {
		var attributes = {
		          'id':                 'video',
		          'name':               'player1'
		       };
	}	
	
	$("#vid" + flashvars.id + "Comments").hide();
	
	swfobject.embedSWF(baseUrl + '/swf/gddflvplayer.swf', 'vid' + flashvars.id + 'Video', width, height, '8', 'false', flashvars, params, attributes);
	$('#vid' + flashvars.id + 'Related').load(baseUrl + '/ajax/relatedvideos/id/' + flashvars.gId);
	$('#vidComments').load(baseUrl + '/ajax/videocomments/id/' + flashvars.id, function() {
		$('#vidComments').slideDown('slow');
		boxy.resize(width + relatedSize , null, showVideoLightbox(boxy));
		boxy.center();
		$('.boxy-inner').attr('class', 'boxy-innerVideo');
		videoLoading = false;
	});
		
    
    
    //$('.boxy-wrapper').css('top', '310px');
    
}
var showVideoLightbox = function(boxy) { boxy.show();  };

function playVideo(flashvars, params, attributes, width, height)
{
	
	if (!width)  width  = 520;
	if (!height) height = 436; // +46
	
	var relatedSize = 350;
	if (!params) {
		var params = {
		          'allowFullScreen':    'true',
		          'allowScriptAccess':  'always',
		          'bgcolor':            '#62636B',
		          'quality':            'best',
		          'scale':              'noscale'
		       };		       		
	}
	if (!attributes) {
		var attributes = {
		          'id':                 'video',
		          'name':               'player1'
		       };
	}	

	$('.boxyVideo').html("<div id=\"vid" + flashvars.id + "Video\"></div>");
    swfobject.embedSWF(baseUrl + '/swf/gddflvplayer.swf', "vid" + flashvars.id + "Video", width, height, '8', 'false', flashvars, params, attributes);
	$('#vidComments').load(baseUrl + '/ajax/videocomments/id/' + flashvars.id, function() {
		$('#vidComments').slideDown('slow');
	});    
    
}



