$(function(){
    /*    $('#banner_msg .container').innerfade({
     speed: 1000,
     timeout: 6000,
     type: 'random_start',
     containerheight: '1.5em'
     });*/
/*    $('#banner_msg_container').cycle({
        fx: 'scrollUp',
        timeout: 6000,
        easing: 'backinout'
    });*/
    
	popUpBox();	
	member_info();   
	fixedHomePosition();
	bgImgResize();  

	
/*    $('#msg_banner_all').cycle({
        fx: 'custom',
        sync: 0,
        cssBefore: {
            top: 0,
            left: 260,
            display: 'block'
        },
        animIn: {
            left: 0,
        },
        animOut: {
            top: 260,
        },
        delay: 1000,
        timeout: 10000
    });*/
    //@cc_on document.execCommand("BackgroundImageCache", false, true);
	
    // Live chat
    var live_chat_dialog = '<iframe src="http://www.google.com/talk/service/badge/Show?tk=z01q6amlqvrm91b5h7t9bvuj291mo8shao0t1t6a7c9lqm89de1tdnm4e8hlvkm45ijptntlodn0cro3hvmt8vq48215lstogrthd1q6rgfg3fo0stmqqnaj93s589lscpvk41i6cme4ptn6nvce4iegdqji3ohgc02q00ja5rltjs843sefmi1rui7blur5a5k&amp;w=159&amp;h=36" allowtransparency="true" frameborder="0" height="36" width="159"></iframe>';
    $('img.live_chat').click(function(){
        if ($('div.live_chat_dialog')) {
            $('div.live_chat_dialog').remove();
        }
        $(live_chat_dialog).dialog({
            dialogClass: 'live_chat_dialog',
            title: 'Live Chat',
            width: 225,
            height: 150,
            position: 'center'
        });
    });
    
    // TV Ad
    $("img.tv_ad, a.tv_ad").colorbox({
        innerWidth: 425,
        innerHeight: 344,
        hasOverlay: false,
        iframe: true
    });
	
	// Fix IE Bug
	if ($.browser.msie){
		 $share_height = $('#share').height();
	    $('#share > .transparency').height($share_height);
	    
	    $quick_height = $('#quick').height();
	    $('#quick > .transparency').height($quick_height);
	}
});

// resize call functions
$(window).resize(function(){
	fixedHomePosition();	
	bgImgResize();	
});

//---------------------------bgImgResize---------------------------
function bgImgResize() {
	var t = $('#body_background');

	//Define image ratio
	var ratio = 3/4;

	//Gather browser and current image size
	var imagewidth = t.width();
	var imageheight = t.height();
	var browserwidth = $(window).width();
	var browserheight = $(window).height();
	var minW = browserwidth > 950 ? browserwidth : 950;
	var minH = browserheight > 600 ? browserheight : 600;	

	//Resize image to proper ratio
	if ((browserheight/browserwidth) > ratio){
	    t.height(browserheight);
	    t.width(browserheight / ratio);
	    t.children().height(browserheight);
	    t.children().width(browserheight / ratio);
	} else {
	    t.width(browserwidth);
	    t.height(browserheight);
	    t.children().width(browserwidth);
	    t.children().height(browserwidth * ratio);
	}

	t.children().css('left', (browserwidth - t.width())/2);
	t.children().css('top', (browserheight - t.height())/2);
}
//---------------------------member info---------------------------
function member_info(){	
	$("#username").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    }).blur(function()
	{
        if ($(this).val() == "")
        {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });    
    $("#username").blur();
    $('#password-clear').show();
    $('#password').hide();

    $('#password-clear').focus(function() {
        $('#password-clear').hide();
        $('#password').show();
        $('#password').focus();
    });
    $('#password').blur(function() {
        if($('#password').val() == '') {
            $('#password-clear').show();
            $('#password').hide();
        }
    }); 
}
//---------------------------fixedHomePosition---------------------------
function fixedHomePosition(){
	var browserWidth = $(window).width();
	var browserHeight = $(window).height();	
	var minBrowserWidth = browserWidth > 950 ? browserWidth : 950;
	var minBrowserHeight = browserHeight > 600 ? browserHeight : 600;

	//Fix Banner Message
	if ($("#banner_msg").css('top') != undefined) {
		var top = parseInt($('#banner_msg').css('top').replace('px',''));
		var maxBannerMsgTop = top > (minBrowserHeight-270) ? (minBrowserHeight - 270) : top;		
		$('#banner_msg').css('top',maxBannerMsgTop+'px')
    }	
};

//---------------------------pop-up box---------------------------
function popUpBox(){
	$(".colorbox").colorbox({
		width:"80%", 				
		height:"70%", 
		maxWidth:"1024px", 
		maxHeight:"768px", 
		hasOverlay: false,
		iframe:true
	});;
	$(".colorbox_img").colorbox({

		maxWidth:"80%", 
		maxHeight:"80%", 
		hasOverlay: false	
	});;
	$("#colorbox").draggable({
		zIndex: 	99999,
		ghosting:	false,
		opacity: 	0.6,
		containment : 'parent'
    });
}

//--------------------------flost banner----------------
/*function fadeIn(){
	$("#msgbanner").fadeIn(500);
}
function fadeOut(){
	$("#msgbanner").fadeOut(500);
}
function fade(){
	setTimeout("fadeOut();",1000);
	setTimeout("fadeIn();",3000);
}*/

function msgbanner_magnify(){
	
	$('div #msgbanner').animate({'height':'210px','width':'222px','bottom':'1px'},150);
	$('.flobanbg').animate({'height':'210px','width':'222px'},150);
	$('.flobanimg').animate({'height':'114.4px','width':'200px'},150);
}
function msgbanner_reduce(){
	$('div #msgbanner').animate({'height':'175px','width':'185px','bottom':'20px'},150);
	$('.flobanbg').animate({'height':'175px','width':'185px'},150);
	$('.flobanimg').animate({'height':'88px','width':'163px'},150);
}
function focus_efficacy(){
setTimeout("msgbanner_magnify();",0);
setTimeout("msgbanner_reduce();",200);
setTimeout("msgbanner_magnify();",400);
setTimeout("msgbanner_reduce();",600);
}
setInterval("focus_efficacy();",6000);
