// JavaScript Document

jQuery(function(){
	jQuery.extend(jQuery.fn.disableTextSelect = function() {
		return this.each(function(){
			if(jQuery.browser.mozilla){//Firefox
				jQuery(this).css('MozUserSelect','none');
			}else if(jQuery.browser.msie){//IE
				jQuery(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				jQuery(this).mousedown(function(){return false;});
			}
		});
	});
	//No text selection on elements with a class of 'noSelect'
});


(function($) {
if(!document.defaultView || !document.defaultView.getComputedStyle){
    var oldCurCSS = jQuery.curCSS;
    jQuery.curCSS = function(elem, name, force){
        if(name === 'background-position'){
            name = 'backgroundPosition';
        }
        if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
            return oldCurCSS.apply(this, arguments);
        }
        var style = elem.style;
        if ( !force && style && style[ name ] ){
            return style[ name ];
        }
        return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
    };
}

var oldAnim = $.fn.animate;
$.fn.animate = function(prop){
    if('background-position' in prop){
        prop.backgroundPosition = prop['background-position'];
        delete prop['background-position'];
    }
    if('backgroundPosition' in prop){
        prop.backgroundPosition = '('+ prop.backgroundPosition + ')';
    }
    return oldAnim.apply(this, arguments);
};

function toArray(strg){
    strg = strg.replace(/left|top/g,'0px');
    strg = strg.replace(/right|bottom/g,'100%');
    strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
    var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
    return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}

$.fx.step.backgroundPosition = function(fx) {
    if (!fx.bgPosReady) {
        var start = $.curCSS(fx.elem,'backgroundPosition');

        if(!start){//FF2 no inline-style fallback
            start = '0px 0px';
        }

        start = toArray(start);

        fx.start = [start[0],start[2]];

        var end = toArray(fx.end);
        fx.end = [end[0],end[2]];

        fx.unit = [end[1],end[3]];
        fx.bgPosReady = true;
    }

    var nowPosX = [];
    nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
    nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
    fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
};
})(jQuery);


function pageWidth() {
 return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

jQuery(window).resize(function () {
	//jQuery.pos = "time1";
	//if (jQuery('#time_slider').css("left") == "auto") {
	//	jQuery('#time_slider').css("left", jQuery('#time_slider').position.left);
	//}	
	
	//if (jQuery.pos) {
	//	jQuery('#time_slider').css("left", jQuery("."+jQuery.pos).position.left);
	//} else {
	//	jQuery('#time_slider').css("left", jQuery(".time1").position.left);
	//}
	
	//alert(jQuery(".time1").position.left);
	
	wdth = parseInt(jQuery('div#container').width(),10);
	//jQuery('div#status').html(wdth);
	if (pageWidth() <= 1245) {
		if (jQuery("div[class='of1']")) {
			jQuery("div[class*='of']").css({'width' : '25%'});
			jQuery("div[class*='of']:eq(4)").css({'display' : 'none'});
			jQuery("div[class*='o2f']").css({'width' : '25%'});
			jQuery("div[class*='o2f']:eq(4)").css({'display' : 'none'});
			jQuery("div[class*='o3f']").css({'width' : '20%'});
			jQuery("div[class*='o3f']:eq(5)").css({'display' : 'none'});
			/*jQuery("div.bignews").fadeOut("fast", function(){
				jQuery("div.smallnews").html(jQuery.news).fadeIn("fast", function(){ 
					jQuery("div.bignews").html("");
					jQuery(".mainnews").css("float", "none");
				});			
			});*/
			jQuery(".mainnews").css("float", "none");
			jQuery("div[id*='shedule']").css({'width' : '45%'});
		}
		jQuery("div[id='banner']").css({'display' : 'none'});
		//if (pageWidth() <= 994) {
			//jQuery("ul#newmail").css('right',pageWidth()-wdth+'px');
			//jQuery("div#mailcontent").css('right',pageWidth()-wdth+'px');
		//} else {
		//	jQuery("ul#newmail").css('right','11px');
		//	jQuery("div#mailcontent").css('right','13px');
		//}
	} else {
		jQuery("div[id='banner']").css({'display' : 'inline'});
		if (jQuery("div[class='of1']")) {
			//jQuery("div[id*='of']:eq(4)").css({'display' : 'inline'});
			jQuery("div[class*='of']:eq(4)").fadeIn("slow");
			jQuery("div[class*='of']").css({'width' : '20%'});
			//jQuery("div[id*='o2f']:eq(4)").css({'display' : 'inline'});
			jQuery("div[class*='o2f']:eq(4)").fadeIn("slow");
			jQuery("div[class*='o2f']").css({'width' : '20%'});
			
			jQuery("div[class*='o3f']").css({'width' : '17%'});
			jQuery("div[class*='o3f']:eq(5)").fadeIn("slow").css({'width' : '15%'});
			
			/*jQuery("div.smallnews").fadeOut("fast", function(){
				jQuery("div.bignews").html(jQuery.news).fadeIn("fast", function(){ 
					jQuery("div.smallnews").html("");
					jQuery(".mainnews").css("float", "left");
				});
			});*/
			jQuery(".mainnews").css("float", "left");
		}
		jQuery("div[id*='shedule']").css({'width' : '55%'});
		//if (pageWidth() >= 1455) {
			
		//} else {
		//	jQuery("ul#newmail").css('left',wdth+'px');
		//	jQuery("div#mailcontent").css('left',wdth+'px');
		//}
	}
	
	if (jQuery.browser.msie) {
		jQuery(".allmsg").css('zoom','1').css('right',pageWidth()-wdth+11+'px');
		//jQuery("div#mailcontent").css('zoom','1').css('right',pageWidth()-wdth+13+'px');
	} else {
		jQuery(".allmsg").css('zoom','1').css('right',pageWidth()-wdth-5+'px');
		//jQuery("div#mailcontent").css('zoom','1').css('right',pageWidth()-wdth-3+'px');
	}
		//	jQuery('.week').html(wdth);
			//jQuery("ul#newmail").css('left',wdth);
			//jQuery("div#mailcontent").css('left',wdth);
	
	});

jQuery(document).ready(function() {
	//jQuery.news = jQuery("div.bignews").html();
	jQuery(window).trigger('resize');
});

	
