// default
/*
var d		= new Date();
var month	= new Array(12);

month[0]	= "january";
month[1]	= "february";
month[2]	= "march";
month[3]	= "april";
month[4]	= "may";
month[5]	= "june";
month[6]	= "july";
month[7]	= "august";
month[8]	= "september";
month[9]	= "october";
month[10]	= "november";
month[11]	= "december";

var currentMonth = '';
var startMonth = month[d.getMonth()];

Date.prototype.getWeek = function() {
    var determinedate = new Date();
    determinedate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate());
    var D = determinedate.getDay();
    if(D == 0) D = 7;
    determinedate.setDate(determinedate.getDate() + (4 - D));
    var YN = determinedate.getFullYear();
    var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
    var WN = 1 + Math.floor(ZBDoCY / 7);
    return WN;
}

var currentWeek = 0;
var startWeek	= d.getWeek();

if(startMonth == 'march'){
	startWeek = startWeek - 8;
}else if(startMonth == 'april'){
	startWeek = startWeek - 12;
}else if(startMonth == 'may'){
	startWeek = startWeek - 16;
}
*/


//
$.postJSON = function (url, data, callback) {
	$.post(url, data, callback, 'json');
};

$(function(){
	
	//
	$.ajaxSetup({ 
			scriptCharset: "utf-8"
	});
	
	// navigation
	//$('#navigation>ul>li').mouseover(function(){ $(this).children('ul').css({display:'block'})}).mouseout(function(){ $(this).children('ul').css({display:'none'})});
	
	//
	//$('.cal_month,.cal_row').click(function(){ return false; });
	//$('#calendar>.week_6,.weekInfo').hide();
	//$('.march_1').show();
	//changeMonth(startMonth);
	
	$('.buy,.buy_image').click(function() { 
        $.blockUI({
			message: $('#buyContent'),
			css: {
				top:  ($(window).height() - $('#buyContent').height()) /2 + 'px', 
                left: ($(window).width() - 648) /2 + 'px', 
				width: '648px',
				borderColor: '#3f4246',
				cursor: 'auto'
			}
		}); 
        $('.blockOverlay,#close').attr('title','Click to close').css({cursor: 'pointer'}).click($.unblockUI);
		pageTracker._trackEvent('Buy', 'Click', document.location);
    });
	
});

function changeMonth(month){
	currentWeek = 0;
	
	if(currentMonth == '' || month == startMonth){
		changeWeek(startWeek);
	} else {
		changeWeek(1);
	}
	
	currentMonth = month;
	
	var xPos = 0;
	var xDelay = 0;
	
	switch(month){
		case 'march':
			xPos = 0;
			$('#calendar>.week_6').slideUp();
			break;
		case 'april':
			xPos = -640;
			$('#calendar>.week_6').slideUp();
			break;
		case 'may':
			xPos = -1280;
			$('#calendar>.week_6').slideDown();
			break;
		default:
			break;
	}
	
	$('#calendar>.month').animate({backgroundPosition: xPos + 'px 0px'});
	$('#calendar>.week_1').delay(xDelay).animate({backgroundPosition: xPos + 'px -70px'});
	$('#calendar>.week_2').delay(xDelay * 2).animate({backgroundPosition: xPos + 'px -142px'});
	$('#calendar>.week_3').delay(xDelay * 3).animate({backgroundPosition: xPos + 'px -214px'});
	$('#calendar>.week_4').delay(xDelay * 4).animate({backgroundPosition: xPos + 'px -286px'});
	$('#calendar>.week_5').delay(xDelay * 5).animate({backgroundPosition: xPos + 'px -358px'});
	$('#calendar>.week_6').css({backgroundPosition: xPos + 'px -430px'});

}

function changeWeek(week){

	if(currentWeek != week){
		currentWeek = week;
		$('.cal_row').removeClass('sel');
		$('.week_' + currentWeek).addClass('sel');
		$('.weekInfo:visible').fadeOut(function(){
			$('.' + currentMonth + '_' + currentWeek).fadeIn();
		});
	}

}
