//Onair
        var onair = {
                tmpl: jQuery('#onair .template').clone(true).removeAttr('class'),
                xml: '',
                page: 1,
                perpage: 3,
                pages: 0
            },

            showfeed = function() {
                var start = onair.page * onair.perpage - onair.perpage,
                    end = onair.page * onair.perpage;
                //parse xml feed
                $('#onair .feed').empty();
                jQuery(onair.xml).find('CBSCS_SCHEDULE:contains("Master")').slice(start, end).each(function(i) {
                    // create clone from template row								 

                    var tmpl = jQuery(onair.tmpl).clone(true).attr({ id: 'row' + i });
                                        
                    jQuery('#onair .feed').append(tmpl);
                    
                    //format the time
                    var this_date = jQuery(this).find('START_TIME').text(); //Date.parse(jQuery(this).find('START_TIME').text());
		    
                    var formatted_time = Date.parse(this_date); //"MMMM dd, yyyy - hh:mm tt"
                    var show_date = formatted_time.toString('h:mm tt - dddd, MMMM d, yyyy');
                    //var formatted_time = dateFormat(this_date, "ddd, mmm d h:MMtt"); //using plugin here
                    
                    //console.log('the date is: ' + show_date);
                    
                    // add xml into row template
					//tmpl.find('.dayofweek').html(jQuery(this).find('SCHEDULE_DAY').text());		//hide for now since START_TIME has all the info we need (uses ISO8601 date format)
                    tmpl.find('.pubdate').attr({ title: jQuery(this).find('START_TIME').text()}); 	//write ISO time into time attribute this isn't necessary but it keeps with standard formatting
                    tmpl.find('.pubdate').html(show_date);
					//tmpl.find('.pubdate').timeago(d);												//if you ever want to use nice formatting, (2 hours ago, 15 minutes ago, etc)
                    tmpl.find('.title').html(jQuery(this).find('SERIES').text());
                    tmpl.find('.description').html(jQuery(this).find('SHOW_TITLE').text());
															
                    tmpl.fadeIn(1500);
                    
                    
                }); //close each(
            };
        
        	/*  
        		--SHOW SAMPLE--
        	
				<CBSCS_SCHEDULE>
					<SCHEDULE_DAY>Wednesday</SCHEDULE_DAY>
					<SCHEDULE_DATE>2010-12-08T00:00:00</SCHEDULE_DATE>
					<START_TIME>2010-12-08T09:00:00</START_TIME>
					<END_TIME>2010-12-08T10:00:00</END_TIME>
					<SHOW_TITLE>The Tony Barnhart Show presented by Bass Pro Shops - 12/07/10</SHOW_TITLE>
					<SHOW_DESCRIPTION xsi:nil="true"/>
					<SPORT xsi:nil="true"/>
					<SERIES>The Tony Barnhart Show Encore</SERIES>
					<RATING>TVG</RATING>
					<GENDER xsi:nil="true"/>
					<DIVISION xsi:nil="true"/>
					<HOME_TEAM xsi:nil="true"/>
					<AWAY_TEAM xsi:nil="true"/>
					<HOME_CONFERENCE xsi:nil="true"/>
					<AWAY_CONFERENCE xsi:nil="true"/>
					<NOTE/>
					<LOG_TYPE>Master</LOG_TYPE>
				</CBSCS_SCHEDULE>
				
				
				--GAME SAMPLE--

				<CBSCS_SCHEDULE>
					<SCHEDULE_DAY>Thursday</SCHEDULE_DAY>
					<SCHEDULE_DATE>2010-12-09T00:00:00</SCHEDULE_DATE>
					<START_TIME>2010-12-09T13:00:00</START_TIME>
					<END_TIME>2010-12-09T16:00:00</END_TIME>
					<SHOW_TITLE>NCAA Football: Army vs.Navy Football 1999</SHOW_TITLE>
					<SHOW_DESCRIPTION>1999</SHOW_DESCRIPTION>
					<SPORT>Football</SPORT>
					<SERIES>CBS Sports Football Encore</SERIES>
					<RATING>TVG</RATING>
					<GENDER>Men's</GENDER>
					<DIVISION>N/A</DIVISION>
					<HOME_TEAM>N/A</HOME_TEAM>
					<AWAY_TEAM>N/A</AWAY_TEAM>
					<HOME_CONFERENCE>N/A</HOME_CONFERENCE>
					<AWAY_CONFERENCE>N/A</AWAY_CONFERENCE>
					<NOTE>IN-HOUSE AS OF 5/15/08</NOTE>
					<LOG_TYPE>Master</LOG_TYPE>
				</CBSCS_SCHEDULE>				
				        	
			*/        	
        	
        	
        	
        
        jQuery(function() {
        
        	var oaDate = new Date(),
			day = oaDate.getDate(),
			month = oaDate.getMonth() + 1,
			year = oaDate.getFullYear();
			
        
            jQuery.ajax({
                type: 'GET',
                //url: 'http://www.cbscollegesports.com/schedule/xml.php?type=calendar&type=calendar', //&month=' + month + '&day=' + day + '&year=' + year,
                url: './schedule_php/cbscs_schedule.xml',
                async: true,
                global: false,
                cache: false,
                dataType: 'xml',
    
                success: function(data) {
                    onair.xml = data;
                    onair.pages = Math.ceil(jQuery(onair.xml).find('CBSCS_SCHEDULE:contains("Master")').length / onair.perpage);
					//                    onair.pages = Math.ceil(jQuery(onair.xml).find('CBSCS_SCHEDULE').length / onair.perpage);                    
                    if (onair.pages > 0)
                        jQuery('#onair .next').removeClass('inactive');
                    showfeed();
                },
                
                error: function() {
                    //console.log('error');
                    //handle error in here, maybe some default text or something
                }
            }); //close jQuery.ajax(
            
            jQuery('#onair .next').bind('click', function() {
                if (jQuery(this).hasClass('inactive')) return false;
                onair.page++;
                showfeed();
                if (onair.page === onair.pages) jQuery(this).addClass('inactive');
                if (onair.page > 1) jQuery('#onair .prev').removeClass('inactive');
                return false;
            });

            jQuery('#onair .prev').bind('click', function() {
                if (jQuery(this).hasClass('inactive')) return false;
                onair.page--;
                showfeed();
                if (onair.page === 1) jQuery(this).addClass('inactive');
                if (onair.page < onair.pages) jQuery('#onair .next').removeClass('inactive');
                return false;
            });
        }); //close jQuery.()
