/**
 * Created by IntelliJ IDEA.
 * User: chris
 * Date: Jun 30, 2010
 * Time: 3:00:53 PM
 * To change this template use File | Settings | File Templates.
 */

$(document).ready(function(){
    $.fn.qtip.styles.aqua = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#099'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#099',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.blue = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#09f'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#09f',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.cobalt = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#6777ab'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#6777ab',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.dust = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#b09461'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#b09461',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.green = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#0c0'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#0c0',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.grey = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#888'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#888',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.moss = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#878C26'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#878C26',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.og = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#c00'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#c00',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.orange = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#f90'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#f90',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.pink = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#f06'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#f06',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.purple = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#90f'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#90f',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.red = {
        width: 238,
        padding:0,
        background: '#222',
        border: {
            width: 7,
            radius: 5,
            color: '#f00'
        },
        tip: {
            corner: 'leftMiddle',
            color: '#f00',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $.fn.qtip.styles.ghost = {
        name: 'dark',
        padding:0,
        border: {
            width: 7,
            radius: 5
        },
        width: 238,
        tip: {
            corner: 'leftMiddle',
            color: '#6699CC',
            size: {
                x: 22,
                y : 12
            }
        }
    }
    $('#full_calendar').fullCalendar({
            viewDisplay: function(view) {
               var start_date = $.fullCalendar.formatDate(view.visStart, 'yyyy-MM-dd HH:mm:ss');
               var end_date = $.fullCalendar.formatDate(view.visEnd, 'yyyy-MM-dd HH:mm:ss');
               load_dates({start_date:start_date, end_date:end_date});
            },
            eventRender: function(event, element) {
                element.qtip({
                    content: event.tip
                    ,position: {
                        corner: {
                            target: 'rightMiddle',
                            tooltip: 'leftMiddle'
                        }
                    }
                    ,style: event.style
                });
            },
            loading: function(bool) {
        alert(bool);
    },
        header: {
            left: '',
            center: 'title',
            right: 'today,month,basicWeek prev,next'
        },
        dayClick: function(date, allDay, jsEvent, view) {
            var data = { criteria : $.fullCalendar.formatDate(date, 'd-M-yyyy') };
            $.ajax({
                 type: 'POST',
                 url: 'calendar/shows_by_day/',
                 data: data,
                 async: false,
                 dataType: 'html',
                 success: function(html) {
                     $('#calendar').empty().html(html);
                 }
             });
        }
    });
});

function load_dates(dates)
{
    $.ajax({
        type: 'POST',
        url: 'calendar/get_month_events/',
        data: dates,
        dataType: 'json',
        async: false,
        success: function(shows) {
            $('#full_calendar').fullCalendar( 'removeEvents' );
            $('#full_calendar').fullCalendar('addEventSource',shows);
        }
//                ,
//                error:function (xhr, ajaxOptions, thrownError){
//                    alert(xhr.status);
//                    alert(thrownError);
//                }
    });
}
