// json2 parser
if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?'0'+n:n}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z':null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key)}if(typeof rep==='function'){value=rep.call(holder,key,value)}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null'}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null'}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' '}}else if(typeof space==='string'){indent=space}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}return str('',{'':value})}}if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j}throw new SyntaxError('JSON.parse');}}}());



/*
 * masnsports.com global javascript library
 * jquery 1.4 is called from CDN
 * author: Jonathan Hartman
 */
var masn = {

	docRoot: null, // must be set BEFORE many of the methods below can run
        fireToolsFunctions: null, // dynamically load jquery tools, only if needed

    // bells and whistles used on all pages (initialize AFTER page load)
    // dependency: jquery 1.4
    bells: {
        init: function(){
            // listener to clear text boxes on click
            $('input.pretext').click(function(){
                if(!$(this).hasClass('flagClicked')){
                    $(this).val('').removeClass('pretext').addClass('flagClicked');
                }
            })

            if(masn.fireToolsFunctions){
                $.getScript(masn.docRoot+'jquery.tools.min.js',function(){
                    $.each(masn.fireToolsFunctions,function(k,v){ eval('masn.'+v+'.init()') });
                })
            }

        }
    },

	// lazy load the large background images
	// requires that the masn.docRoot variable be set BEFORE being called!
	big_bg: {
		init: function(picname,bgcolor){
			if(picname){
				$('body').css('background',bgcolor+' url('+masn.docRoot+'gfx/big_backgrounds/bg_'+picname+'_gradient.jpg) repeat-x fixed 0 0');
				$('#superback').css('background','url('+masn.docRoot+'gfx/big_backgrounds/bg_'+picname+'.jpg) no-repeat fixed 50% 0');
			}
		}
	},

    // large menus for main site navigation
    // dependency: jquery 1.4
    mega_menus: {
        init: function(){
            $('li','ul#main-nav').bind({
                mouseenter: function(){
                    $(this).find('a').addClass('active')
                    $(this).find('.cMega').css('display','block');
                },
                mouseleave: function(){
                    $(this).find('a').removeClass('active')
                    $(this).find('.cMega').css('display','none')
                }
            })

            // lazy load all the background menu gradients
            $('div.cMega','li#nav-masn').css('background','#3152bb url('+masn.docRoot+'1masnsports/mt/mt-static/themes/masn/gfx/template/menu_bgs/masn.jpg) repeat-x 0 0');
            $('div.cMega','li#nav-orioles').css('background','#f94f24 url('+masn.docRoot+'1masnsports/mt/mt-static/themes/masn/gfx/template/menu_bgs/orioles.jpg) repeat-x 0 0');
            $('div.cMega','li#nav-nats').css('background','#dc2223 url('+masn.docRoot+'1masnsports/mt/mt-static/themes/masn/gfx/template/menu_bgs/nats.jpg) repeat-x 0 0');
            $('div.cMega','li#nav-ravens').css('background','#421b78 url('+masn.docRoot+'1masnsports/mt/mt-static/themes/masn/gfx/template/menu_bgs/ravens.jpg) repeat-x 0 0');
            $('div.cMega','li#nav-media').css('background','#ffc73e url('+masn.docRoot+'1masnsports/mt/mt-static/themes/masn/gfx/template/menu_bgs/media.jpg) repeat-x 0 0');
        }
    },

    fix_ie6: {
        init: function(){
            // available: http://labs.unitinteractive.com/unitpngfix.php
            var clear="http://masnsports.com/1masnsports/mt/mt-static/themes/masn/gfx/template/ie6_pngfix.gif"; //path to clear.gif
            document.write('<script type="text/javascript" id="ct" defer="defer" src="javascript:void(0)"><\/script>');var ct=document.getElementById("ct");ct.onreadystatechange=function(){pngfix()};pngfix=function(){var els=document.getElementsByTagName('*'),ip=/\.png/i,al="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='",i=els.length,uels=new Array(),c=0;while(i-->0){if(els[i].className.match(/unitPng/)){uels[c]=els[i];c++;}}if(uels.length==0)pfx(els);else pfx(uels);function pfx(els){i=els.length;while(i-->0){var el=els[i],es=el.style,elc=el.currentStyle,elb=elc.backgroundImage;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter=al+el.src+"',sizingMethod='crop')";el.src=clear;}else{if(elb.match(ip)){var path=elb.split('"'),rep=(elc.backgroundRepeat=='no-repeat')?'crop':'scale',elkids=el.getElementsByTagName('*'),j=elkids.length;es.filter=al+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';if(j!=0){if(elc.position!="absolute")es.position='static';while(j-->0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}};};

            // clean up the document for crud ie6 can't handle AFTER the png fix
            $('.dropbottom').remove();

        }
    },

    // create hover state for extrude area containing an advertisement (only one per page)
    // dependency: jquery 1.4
    extrude_advert: {
        init: function(height){
            var ad_hover_state = false;
            $('#jqtrigger-ad-hover').mouseenter(function(e){
               if(!ad_hover_state){$('#jqtrigger-expanding-adspace').animate({height:'+='+height},200);}
               ad_hover_state = true;
               ($(e.target).parent()).mouseleave(function(){
                   if(ad_hover_state){$(this).animate({height:'-='+height},200)}
                   ad_hover_state = false;reset();
               })
            })
        }
    },

	pgrid: {
        init:function(){
			
            $.getScript(masn.docRoot+'pgrid/jquery-ui.min.js',function(){
                $('#datepicker').datepicker({
                    showOn: 'button',
                    buttonImage: 'pgrid/ico-calendar.png',
                    buttonImageOnly:true,
                    onSelect: function(dateText,inst){
                        masn.pgrid.ajaxGetSched(dateText)
                        $('#showing-sched-date').empty().append(dateText)
                    }
                });
            })

            $.getScript(masn.docRoot+'pgrid/jScrollPane.js',function(){
                $.getScript(masn.docRoot+'pgrid/jquery.mousewheel.js') // if the jScrollpage gets loaded, load the mousewheel plugin
                masn.pgrid.ajaxGetSched('today');
            })
			
        },
        ajaxGetSched: function(date){
            /*$.get(masn.docRoot+'pgrid/load_programming.php5',
            { getSchedule: date },function(data){
                $('#pane4').empty();
                $('#pane4').append(data).css('overflow','auto')

                $('#pane4').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});

                // this allows you to click a link to add content to #pane4 and shows how to
                // reinitialise the scrollbars when you have done this.
                $('#add-content').bind('click', function(){$('#pane4').append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});});

                // and this allows you to click the link to reduce the amount of content in
                // #pane4 and reinitialise the scrollbars.
                $('#remove-content').bind('click',function(){$('#pane4').empty().append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});});
            },'html')*/
			
			$.get(masn.docRoot+'_grid/grid.process.php5',{_date:date},function(data){
				$('.holder','#tvGrid').empty().append( $('<div id="pane4"></div>') )
				$('#pane4').empty();
                $('#pane4').append(data).css('overflow','auto')

                $('#pane4').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});

                // this allows you to click a link to add content to #pane4 and shows how to
                // reinitialise the scrollbars when you have done this.
                $('#add-content').bind('click', function(){$('#pane4').append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});});

                // and this allows you to click the link to reduce the amount of content in
                // #pane4 and reinitialise the scrollbars.
                $('#remove-content').bind('click',function(){$('#pane4').empty().append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});});
			})
        }
    },

    /*****************************************************************
    * DEPENDENCY: jQuery, jQueryTools
    * Featured images/videos/etc scroller plugin
    * TODO: implement lazy loading of scrollable elements
    *****************************************************************/
    scroller: {
        init: function(){

            var scroll = $("#scrollable").scrollable({
                size: 1,
                activeClass: "active",
                speed:550,
                onSeek: function(e,index){
                    $("a.active", '#cScrollTrack ul li').removeClass("active");
                    $("a","#cScrollTrack ul li:eq("+index+")").addClass("active");
                }
            }).autoscroll({autoplay:true,autopause:true,interval:6500,api:true});

            $("a","#cScrollTrack ul li").mouseover(function(){
                scroll.pause();
            }).click(function(){
                scroll.seekTo($(this).attr('rel'));
            })
        }
    },

    grow_subheader: { // beta: expand the subheader when hovered
        init: function(){
            $('#subheading').hover(function(){ $(this).stop().animate({height:'+=200'},250) },function(){ $(this).stop().animate({height:'-=200'},250) })
        }
    }

}

$(function(){

    $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

});




$(document).ready(function()
{		
	var content = $('#dropdown .content');

        // This line controlls the initial state of the expandable header.
        // Write "content.show();" on the folowing line for page to load open, and write "content.hide();" to load collapsed.
	content.hide();
	
	$('#dropdown-tab a').click(function()
	{
			content.slideToggle('medium');
			$(this).toggleClass('open');
			return false;
	});
	
	$('#dropdown form input:not(input.btn_submit)').focus(function()
	{
			$(this).parents('p').siblings('p').removeClass('sel');
			$(this).parents('p').addClass('sel');
			return false;
	});
		
	$('#dropdown form textarea').focus(function()
	{
			$(this).parents('p').siblings('p').removeClass('sel');
			$(this).parents('p').addClass('sel');
			return false;
	});
		
		
	$('#dropdown form input.btn_submit').click(function()
	{
		var form_text = $('p#form_text');
		
		var name = $('#form_name').val();
		var email = $('#form_email').val();
		var message = $('#form_message').val();
		if (name =='' || email =='' || message == '') {
			form_text.text('One or more of the fields was left blank - please try again.');
			return false;
		}
		$.post("masnsports.com", { name: name, email: email, message: message } );
		$('#form_name').val('');
		$('#form_email').val('');
		$('#form_message').val('');
		form_text.text('You should receive a reply within a couple of days.');
		return false;

	});
													
});

