$(document).ready(function(){

    $('.RulesTable thead+tbody tr:nth-child(even)').addClass('EvenRow');

    $(".plusicon").show();
    $(".PurchaseSubTable").hide();
    $(".PurchaseLabel").show();
    $(".plusicon").click(function(){ShowPurchaseTable($(this));});
    $(".minusicon").click(function(){HidePurchaseTable($(this));});
        
    $(".EventListing").click(function(){SelectTicket($(this));});
    
    HideJavascriptObjects();
    
    $(".HoverEffect").hover(
        function(){UsePointer($(this),true)},
        function(){UsePointer($(this),false)}
    );
    
    $("div.overlabel label").overlabel();

});


/* Purchase Page */

function TicketIsPaidFor(element)
{
    element.addClass("ticked");
    element.unbind();
}

function SelectTicket(element)
{
    if (element.length > 0) {
        var varId = parseInt(element.attr("id").replace("eventTicket",""));

        if (element.hasClass("ticked")) {
            element.removeClass("ticked");
            $("#eventTicketId"+varId).attr('checked', false);
        }
        else {
            element.addClass("ticked");
            $("#eventTicketId"+varId).attr('checked', true);
        }
    }
}

/* Payments Page */

function ShowPurchaseTable(Button)
{
  var varID = parseInt(Button.attr("id").replace("plusicon",""));
  Button.hide();
  $("#span"+varID).hide();
  $("#table"+varID).show();
  $("#minusicon"+varID).show();
}

function HidePurchaseTable(Button)
{
  var varID = parseInt(Button.attr("id").replace("minusicon",""));
  Button.hide();
  $("#span"+varID).show();
  $("#table"+varID).hide();
  $("#plusicon"+varID).show();
}

/* OverLabel Technique */

( function( $ ) {
 
    // plugin definition
    $.fn.overlabel = function( options ) {
 
        // build main options before element iteration
        var opts = $.extend( {}, $.fn.overlabel.defaults, options );
 
        var selection = this.filter( 'label[for]' ).map( function() {
 
            var label = $( this );
            var id = label.attr( 'for' );
            var field = document.getElementById( id );
 
            if ( !field ) return;
 
            // build element specific options
            var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
 
            label.addClass( o.label_class );
 
            var hide_label = function() { label.css( o.hide_css ) };
            var show_label = function() { this.value || label.css( o.show_css ) };
 
            $( field )
                 .parent().addClass( o.wrapper_class ).end()
                 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
 
            return this;
 
        } );
 
        return opts.filter ? selection : selection.end();
    };
 
    // publicly accessible defaults
    $.fn.overlabel.defaults = {
 
        label_class:   'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css:      { 'text-indent': '-10000px' },
        show_css:      { 'text-indent': '0px', 'cursor': 'text' },
        filter:        false
 
    };
 
} )( jQuery );


/* Standard Effects */
function HideJavascriptObjects()
{
    $(".JSHide").hide();
}


/* Hover Effect */

function UsePointer(element,pointerRequired)
{
    if (pointerRequired)
        $(element).addClass('HoverEffect');
    else
        $(element).removeClass('HoverEffect');
}

/* Png Fix */

var blank = new Image();
blank.src = 'http://crew.profounddecisions.co.uk/resources/odyssey/images/blank.gif';
var pngFixBrowser;
$(document).ready(function() {
    if ((/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32")) {
        
        $('img.SwapPngToGif').each(function() {SwapPngToGif($(this))});
            
        // get all pngs on page
        $('img[src$=.png]').each(function() {
            fixPngOnLoad(this);
        /*
            if (!this.complete) {
                this.onload = function() { fixPng(this) };
            } else {
                fixPng(this);
            }
            */
        });
    }
});

function SwapPngToGif(element) {
    element.attr({src: element.attr("src").replace(".png",".gif")});
}

function fixPngOnLoad(element) {
    if (!element.complete) {
        element.onload = function() { fixPng(element) };
    } else {
        fixPng(element);
    }
}
 
function fixPng(png) {
    // get src
    var src = png.src;
    // set width and height
    if (!png.style.width) { png.style.width = $(png).width(); }
    if (!png.style.height) { png.style.height = $(png).height(); }
    // replace by blank image
    png.onload = function() { };
    png.src = blank.src;
    // set filter (display original image)
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}




