/* UEFA SiteCatalyst Dynamic Actions */

(function($){
    $(document).ready(function() {
        var sitecatobj = s_gi(s_account);
        sitecatobj.linkTrackVars='events,eVar43';
        sitecatobj.linkTrackEvents='event20';
        sitecatobj.events='event20';


        //hooks list - hook definition = [<jquery selectors>,<UEFA eVar43 value>]
        actionhooks = new Array();
        actionhooks.push(new Array('#ism_myteam #ism_tab_data','fnt stats')); //myteam - stats click
        actionhooks.push(new Array('#ism_myteam #ism_tab_graph','fnt graph'));      //myteam - stats graph click
        actionhooks.push(new Array('#ism_myteam #ism_title_help','fnt help'));     //myteam - help click
        actionhooks.push(new Array(
            "#ism_teamadmin #ism_selection_form input[type='submit']",
            'fnt team details update'
        ));                                                                        //teamadmin - update click
        actionhooks.push(new Array(
            "#ism_eiw_nav #ism_wl_add input[type='submit']",
            'fnt player add to watchlist'
        ));                                                                        //player window - watchlist add
        actionhooks.push(new Array(
            "#ism_eiw_nav #ism_wl_del input[type='submit']",
            'fnt player delete from watchlist'
        ));                                                                        //player window - watchlist delete

        /* combine into custom hook?  */
        actionhooks.push(new Array(
            "#ism_eiw_nav a[href='#summary']",
            'fnt player summary'
        ));                                                                        //player window summary
        actionhooks.push(new Array(
           "#ism_eiw_nav a[href='#history']",
           'fnt player history'
        ));
        actionhooks.push(new Array(
           "#ism_eiw_nav a[href='#fixtures']",
           'fnt player fixtures'
        ));

        actionhooks.push(new Array('#ism_myteam #ism_title_help','fnt help'));     //myteam    - help click
        actionhooks.push(new Array('#ism_transfer #ism_title_help','fnt help'));   //transfers - help click
        actionhooks.push(new Array(
            "#ism_notes_form input[type='submit']",
            'fnt notes update'
        ));                                                                        //notes - submit update


        //bind the events        
        for(var i=0; i < actionhooks.length; i++) {
            $(actionhooks[i][0]).bind(
                'click',
                {eVar43:actionhooks[i][1]},
                function(e) { 
                    //alert(e.data.eVar43);
                    sitecatobj.eVar43=e.data.eVar43;
                    sitecatobj.tl(this,'o','Tool Name');
                    return(true);
                }
            );
        }

        //** non standard binds here **

        //help - category links
        $("div#ism_help a[href*='help.mc?category']").bind('click',function() {
                var category=this.href.split('category=');
            
                sitecatobj.eVar43='fnt help ' + category[1];
                sitecatobj.tl(this,'o','Tool Name');
                return(true);
        });

        //myteam - captain swap
        $("div#ism_myteam select#ism_captain").bind('change',function() {

                sitecatobj.eVar43='fnt captain';
                sitecatobj.tl(this,'o','Tool Name');
                return(true);
        });

        //element filters
        $("#ism_element_filter").bind('change',function() {
                sitecatobj.eVar43='fnt filter';
                sitecatobj.tl(this,'o','Tool Name');
                return(true);
        });

        //myteam  - bench player (live query as image changes)
        $("#ism_myteam #ism_pitch_grid img[src$='out.png']").live('click',function() {
                sitecatobj.eVar43='fnt player';
                sitecatobj.tl(this,'o','Tool Name');
                                return(true);
        });
                


    });

})(jQuery);
