﻿// JavaScript Document
// 圖片滾動
$(document).ready(function(){
	if ($("#slidetexts").html() != null) {
		slideLine('slidetexts', 5000, 32, 34); 
	}
});
var dialog = ({
    'open' : function(container, context, callback){
		var $container = $(container||'.js_dialog');
		if($container.size()<=0){
			$container = $('<div class="js_dialog"></div>').appendTo('body');
		}
		context || (context = {
				title: '',
				content: $container.html(),
				tips: '',
				width: 300,
				height: 200
			});
		var $title		= context.title ? '<div class="js_dialog_title">'+ unescape(context.title) +'</div>' : '';
		var $tips		= context.tips ? '<div class="js_dialog_tips">'+ unescape(context.tips) +'</div>': '';
		var $content	= context.content ? '<div class="js_dialog_content">'+ unescape(context.content) +'</div>':'';
		$context = $title+$tips+$content;
		if( $container.html()!=$context ){
			$container.empty();
			$container.append($title);
			$container.append($content);
			$container.append($tips);
		}
		$container.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			// closeHTML:'<a id="CloseDialogLink" class=”modalCloseImg” title=”Close”></a>',
			closeClass: 'simplemodal-close',
			overlayCss: {
				backgroundColor: '#000',
				cursor: 'normal'
			},
			minHeight: 200,
			minWidth: 300,
			containerCss: {
				height: context.height,
				width: context.width,
				backgroundColor: '#F0FAFF',
				border: '3px solid #B3D1FE',
				overflow: 'auto'
			},
			onShow: function(){
				callback && callback();
			}
		});
	},
	'openAjax': function(container, context, url, data, callback){
		var that = this;
		$.get(url, data, function(response){
			context.content = response || '';
			that.open(container, context, callback);
		});
	},
	'aOpen': function(actObj, callback){
		actObj = $(actObj);
		if( actObj.attr('href') ){
			var that = this;
			var context = {
				title: actObj.attr('title') || '',
				tips: actObj.attr('tips') || '',
				width: actObj.attr('width') || 'auto',
				height: actObj.attr('height') || 'auto'
			};
			$.get(actObj.attr('href'), function(response){
				context.content = response || '';
				that.open(null, context, callback);
			});
		}
		return false;
	},
    // 会员登录弹出窗口
    login:function(loginObj,url) {
        loginObj.load("./?module=dialog&action=login&url="+url);
        loginObj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			// closeHTML:'<a id="CloseDialogLink" class=”modalCloseImg” title=”Close”></a>',
			closeClass: 'simplemodal-close',
            overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                width:450,
				height:245,
                backgroundColor: '#F0FAFF',
                border: '3px solid #B3D1FE'
            }
	    });
    },
    
    // 物件举报
    report:function(reportObj,itemId,classFlag) {
        reportObj.load("./dialog-report.html?itemId="+itemId+"&type="+classFlag);
        reportObj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			closeClass: 'simplemodal-close',
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                width:530,
				height:280,
                backgroundColor: '#F0FAFF',
                border: '3px solid #B3D1FE'
            }
	    });
    },
	
	// 留言回覆
	reply:function(obj,id) {
		obj.load('./dialog-reply-'+id + '.html');
		obj.modal({
            close: true,
			escClose: true,
			overlayClose: true,
			// closeHTML:'<a id="CloseDialogLink" class=”modalCloseImg” title=”Close”></a>',
			closeClass: 'simplemodal-close',
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                height: 300,
                width: 400,
                backgroundColor: '#fff',
                border: '3px solid #ccc'
            }
	    });
	},
    
    // 卖家信用评价
    appraise:function(appraiseObj,itemId) {
        appraiseObj.load("./dialog-appraise.html?itemId="+itemId);
        appraiseObj.modal({
            close: true,
			// closeHTML:'<a id="CloseDialogLink" class=”modalCloseImg” title=”Close”></a>',
			closeClass: 'simplemodal-close',
			escClose: true,
			overlayClose: true,
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                height: 300,
                width: 400,
                backgroundColor: '#fff',
                border: '3px solid #ccc'
            }
	    });
    },
	
	// 弹出提示框
	promptMsg:function(obj,message) {
		obj.modal({
			onShow: function (obj) {
				alert(message);
				// $.modal.close();
			},
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                height: 300,
                width: 400,
                backgroundColor: '#fff',
                border: '3px solid #ccc'
            }
		});
	},
	
	// 明細頁車輛驗證彈出窗口
	authAutoBox:function(obj,itemId){
		obj.load('./dialog-reqAuth-' + Number(itemId) + '.html');
		obj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			closeClass: 'simplemodal-close',
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                width:450,
				height:230,
                backgroundColor: '#F0FAFF',
                border: '3px solid #B3D1FE'
            }
		});
	},
	//更換驗證行動電話
	changeMobile:function(obj,mId){
		obj.load("./?module=dialog&action=changeMobile");
		obj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			closeClass: 'simplemodal-close',
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                width:450,
				height:220,
                backgroundColor: '#F0FAFF',
                border: '3px solid #B3D1FE'
            }
	    });
		return ;
	},
	//手動開啟物件
	autoOpen:function(obj){
		obj.load("./?module=dialog&action=autoOpen");
		obj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
			minWidth: 600,
            containerCss: {
                width:600,
				height:360,
				backgroundColor: '#FFFFFF',
				border: '3px solid RGB(255,189,145)'
            },
			onShow: function(){
				$('#simplemodal-container').width(this.minWidth);
			},
			onResize: function(){
				$('#simplemodal-container').width(this.minWidth);
			}
	    });
		return ;
	},
	//預約看車
	appointment:function(obj,itemId){
		obj.load("./?module=dialog&action=appointment&id="+itemId);
		obj.modal({
			close: true,
			escClose: true,
			overlayClose: true,
			closeClass: 'simplemodal-close',
			overlayCss: {
                backgroundColor: '#000',
                cursor: 'normal'
            },
            containerCss: {
                width:440,
				height:250,
                backgroundColor: '#F0FAFF',
                border: '3px solid #B3D1FE'
            }
	    });
		return ;
	}
});