 jQuery(document).ready(function($) {
        $(".tweet").tweet({
          join_text: "auto",
          username: "leedsticketscom",
          avatar_size: 48,
          count: 3,
          auto_join_text_default: "we said,", 
          auto_join_text_ed: "we",
          auto_join_text_ing: "we were",
          auto_join_text_reply: "we replied",
          auto_join_text_url: "we were checking out",
          loading_text: "loading tweets..."
        });
		 $("#empty").tweet({
          avatar_size: 32,
          count: 4,
          query: "leedsticketscom",
          loading_text: "searching twitter..."
        }).bind("empty", function() { $(this).append("No matching tweets found"); });
      })

$(document).ready(function(){
	$("ul.topnav li a").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
});

$(function(){ $("select, input:checkbox, input:radio, input:file").uniform(); });

$(document).ready(function() {
		$('#featured').removeClass('hide');
    if ($("#slider").length)
    {
        $('#slider').s3Slider({
            timeOut: 6000
        });
    }
  });

$(function(){
  $("#features .subfeatured").hover(function(){
    $(this).stop();
    $(this).animate({"opacity":0.8}, "slow");
  }, function(){
    $(this).stop();
    $(this).animate({"opacity":1}, "slow");
  });
    $("#content-front .entry").hover(function(){
    $(this).stop();
    $(this).animate({"opacity":0.8}, "slow");
  }, function(){
    $(this).stop();
    $(this).animate({"opacity":1}, "slow");
  });
});


$(document).ready( function() {

  var doSubmit = false;

  // Add handlers to the despatch options to determine shipping/non-shipping.
  
  var addrFields = new Array('saddr1', 'saddr2', 'scity', 'scountyprovince',
    'spostalcode', 'scountry');
  
  $("input[name='despatch'][type='radio']").live('click', function() {

    var val = $(this).val();
    $(this).attr("selected", "selected");
    $(this).parent().addClass("checked");
    controlShipping(postal[val]);
  });

  $("#ship_bill").live('click', function() {

    // copy over
    for (index in addrFields)
    {
      var field = addrFields[index];
      var bField = field.replace(/^s?/, 'b');
      var val = "";
      if ($(this).is(":checked"))
      {
        val = $("#" + bField).val();
      }

      $("#" + field).val(val).change();
    }
  });

  selectDespatchOption();

  /**
   * Controls the state of the input fields on the address form
   *
   * @param boolean isPostal
   */
  function controlShipping(isPostal)
  {
    isPostal = (isPostal ? true : false);

    if (isPostal)
    {
      for (index in addrFields)
      {
        var field = addrFields[index];
        $("#" + field).val("").css("background-color", "").attr("disabled", "");
      }
    }
    else
    {
      for (index in addrFields)
      {
        var field = addrFields[index];
        $("#" + field).val(collectionAddress[field])
          .attr("disabled", "disabled");
      }
    }
    $("#ship_bill").attr("disabled", "");
  }

  /**
   * Fires the selection for the despatch options.
   * Sets a default to the first option if nothing is selected.
   *
   * @return void
   */
  function selectDespatchOption()
  {
    if (!$("input[name='despatch']:selected").length)
    {
      var obj = $("input[name='despatch']:first");
    }
    else
    {
      var obj = $("input[name='despatch']:selected");
    }
    obj.click();
    if ($("#ship_bill:checked").length)
    {
      shipBill();
    }
  }

  // Bind submit button to collections check
  $("form[name=addform]").bind("submit", function()
  {
    if (doSubmit)
    {
      return true;
    }

    // Collection type supplied?
    if (typeof collType === 'undefined')
    {
      return true;
    }
    
    // Collection type selected?
    var choice = $("input[name=despatch][type=radio]:checked").val();
    var isCollection = false;
    var haveDatas = false;
    var dataObjs = "";
    for (i in collInfos)
    {
      var elem = collInfos[i];
      if (elem.da_id == choice && elem.type == collType)
      {
        isCollection = true;

        if (elem.data != '' && elem.data)
        {
          dataObjs += "<li>" +
            "<strong>" + elem.shortartist + "</strong>: " +
            elem.data + "</li>";
        }
      }
    }
    if (!isCollection || !dataObjs.length)
    {
      // No specific collection info
      return true;
    }

    // Any popover?
    if (!$("#collections-modal").size())
    {
      // carry on
      return true;
    }

    // We have info to show, show the dialog and return the response
    $("#collections-infos").html(dataObjs);
    $("#collections-modal").dialog(
    {
      modal: true,
      resizable: false,
      title: "Collections information"
    });
    $(".ui-dialog-titlebar-close").remove();
    $("#collections-modal").dialog("option", "buttons",
      {
        "Continue": function() { doSubmit = true; $("form[name=addform]").submit() },
        "Cancel" : function() { doSubmit = false; $("#collections-modal").dialog("destroy"); }
      }
    );

    return false;
  })
});

function breakout()
{
  if (self != top)
  {
    if (document.images)
    {
      top.location.replace(window.location.href);
    } else
    {
      top.location.href = window.location.href;
    }
  }
}

