/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/


// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function()
	{	
		addBookmarkObj.addTextLink("addtobookmarks");
		
		$(".fieldhint").hint();
		
		// Makes links open in new window when they have rel=external
		$("a[rel=external]").attr("target", "_blank");
		// Use below method if using thickbox, matches class rather than rel
		$("a.external-link").attr("target", "_blank");
		
		$("input.btn").hover(function(){
			$(this).addClass("btn_hover");
		},function(){
			$(this).removeClass("btn_hover");
		});
		
		$(".cms_disclaimer").each(function(){
			if ($.trim($(this).text()) == "")
			{
				$(this).remove();
			}
		});
		
		var VidDivsMaxHeight = 0;
		if ($("#toplarge_player_controller").length > 0)
		{
			VidDivsMaxHeight = 0;
			$(".Vid_div").each(function(){
				if (VidDivsMaxHeight < $(this).height())
				{
					VidDivsMaxHeight = $(this).height();
				}
			});
			$(".Vid_div_wrapper").height(VidDivsMaxHeight);
			$(".Vid_div").hide();
		}
		
		$("#toplarge_player_controller a").bind("click",function(ev){
			ev.preventDefault();
			
			var thisLink = $(this);
			var newDiv = $(thisLink.attr("href"));
			var oldDiv = $(".Vid_div_active");
													 
			$("#toplarge_player_controller a.active").removeClass("active");
			thisLink.addClass("active");
			
			oldDiv.stop(true,true).removeClass("Vid_div_active").fadeOut(400,function(){
				newDiv.stop(true,true).addClass("Vid_div_active").fadeIn(400);
			});
				
			var flashvars = { flv: ( thisLink.attr("href").replace("#","") + ".flv" ) };
			var params = { wmode: "transparent", allowfullscreen: true };
			var attributes = {};
			swfobject.embedSWF("assets/video_player.swf", "toplarge_player", "357", "223", "9.0.0", null, flashvars, params, attributes);
		});
		$("#toplarge_player_controller a:first").trigger("click");
		
	});
}

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'fieldhint_blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window),
      ispwd = $input.is('input[type="password"]');

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    function remove_silent() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('');
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      //$form.submit(remove_silent);
      //$win.unload(remove_silent); // handles Firefox's autocomplete

      // clear the pre-defined text when form is submitted
		$form
			.find("input[type='submit'], input[type='image']")
			.not(".fieldhint_bind_applied")
			.addClass("fieldhint_bind_applied")
			.bind("focus mousedown click",function(){
				$(".fieldhint").each(function(){
					if ($(this).val() == $(this).attr("title"))
					{
						$(this).val("");
					}
				});
			})
			.bind("blur mouseleave",function(){
				$(".fieldhint").each(function(){
					if ($.trim($(this).val()) == "")
					{
						$(this).val($(this).attr("title"));
					}
				});
			})
		;
    }
  });
};
