
// ▼LockUP追加箇所　SlideImgの定義　※実行はしていません-------------------------- //
var $lu = new function(){

	var method = {};

	//getElementById
	method.id = function(idName){
		return document.getElementById(idName);
	}
	//getElementsByTagName
	method.tag = function(elm,tagName){
		return elm.getElementsByTagName(tagName);
	}


	/* ------------------------------------------------------------- */
	/* START EventListener */
	/* リスナーの追加と削除 */
	/* ------------------------------------------------------------- */
	method.addEventListener = function(elm,type,func,useCapture){
							if(!elm){return false}
							if(!useCapture){useCapture = false;}
							if(elm.addEventListener){
								elm.addEventListener(type,func,useCapture);
							}else if(elm.attachEvent){
								elm.attachEvent('on' + type,func);
							}else{return false;}
							return true;
						}
	method.removeEventListener = function(elm,type,func,useCapture){
							if(!elm){return false}
							if(!useCapture){useCapture = false;}
							if(elm.removeEventListener){
								elm.removeEventListener(type,func,useCapture);
							}else if(elm.detachEvent){
								elm.detachEvent('on' + type,func);
							}else{return false}
							return true;
						}

return method;
}



function SlideImg(obj){
//	======================================================================
//	サムネイル画像スライドファンクション
// ----------------------------------------------------------------------
//	@obj			:	Object		:	操作するDOM要素のID
//		container 		:	String		:	最上位の親ボックスID
//		slideBox 		:	String		:	サムネイル画像を内包するボックスID//スライドさせるボックス
//		left			:	String		:	プレビューボタンのID
//		right			:	String		:	ネクストボタンのID
//		imgWidth		:	Number		:	サムネイルの幅
//		imgPadding		:	Number		:	サムネイル間の余白
//		length			:	Number		:	表示する数
//		speed			:	Number		:	移動の早さ[省略可]
//		className		:	String		:	プレビューボタン・ネクストボタンにつけるclass名[省略可]
// ----------------------------------------------------------------------
//	return			:	Void		:	
// ----------------------------------------------------------------------
	this.my_container = $lu.id(obj.container);
	this.my_slideBox = $lu.id(obj.slideBox);
	this.my_left = $lu.id(obj.left);
	this.my_right = $lu.id(obj.right);
	this.my_imgWidth = obj.imgWidth;
	this.my_imgPadding = obj.imgPadding;
	this.my_length = obj.length;
	this.my_speed = obj.speed||0.3;
	this.my_endClass = obj.className||'slideimg_off_js';
	this.init();
}

SlideImg.prototype.init = function(){
	var instance = this;
	
	//イベントリスナー
	$lu.addEventListener(this.my_left,'click',function(event){instance.slide('left');});
	$lu.addEventListener(this.my_right,'click',function(event){instance.slide('right')});
	//移動させる距離
	this.maxValue = this.my_imgWidth + this.my_imgPadding;
	//移動中かを示すFlag
	this.slideFlag = false;
	//現在の位置
	this.point = 0;
	//要素の数を取得
	var c = this.my_slideBox.childNodes;
	var len = 0;
	for(var i =0;i<c.length;i++){
		if(c[i].nodeType == 1){
			len++
		}
	}
	//しきい値
	this.leftEnd = 0;
	this.rightEnd = -(this.maxValue*len-this.maxValue*this.my_length);
	//
	this.isLeftSlide = false;
	this.isRightSlide = true;
	
	//左ボタンをoff
	this.my_left.className=this.my_endClass;
	
	
	//高さ調整
	var instance = this;
	var staticH = this.my_slideBox.offsetHeight;
	var timer = setInterval(function(){
		var nowH = instance.my_slideBox.offsetHeight;
		
		if(staticH != nowH){
			instance.my_slideBox.parentNode.style.height = nowH + 'px';
			staticH = nowH;
		}
	},1000);
	
	
}

//slide
SlideImg.prototype.slide = function(type){
	//Flagがtrueの場合はなにもしない
	if(this.slideFlag) return;
	
	//type別処理
	var endPoint;
	if(type == 'left'){
		//isLeftSlideがfalseであればreturn
		if(!this.isLeftSlide) return;
		//最終的な位置
		endPoint = this.point + this.maxValue;
	}else if(type == 'right'){
		//isLeftSlideがfalseであればreturn
		if(!this.isRightSlide) return;
		//最終的な位置
		endPoint = this.point - this.maxValue;
	}else{
		alert('エラー：typeが無効')
	}

	//インスタンスの参照
	var instance = this;
	//移動中かを示すFlagをtrueに
	this.slideFlag = true;
	//移動させる値
	var mValue = this.maxValue;
	var value;
	var slideId = setInterval(function(){
		//移動させる値
		value = (mValue*instance.my_speed <= 1)?1:Math.floor(mValue*instance.my_speed);
		//スタイルシートを変更
		instance.my_slideBox.style.left = (value == 1)?endPoint + 'px':(type == 'right')? instance.point-value + 'px' :instance.point+value + 'px';
		//現在の位置を取得
		instance.point = Math.floor(instance.my_slideBox.style.left.split('px')[0]);
		mValue -= value;
		if((type == 'right' && instance.point <= endPoint)||(type == 'left' && instance.point >= endPoint)){
			clearInterval(slideId);
			//移動中かを示すFlagをfalseに
			instance.slideFlag = false;
			//console.log(instance.point)
			//console.log(instance.rightEnd);
			//しきい値を超えていればfalseにする
			instance.isLeftSlide = (instance.point<instance.leftEnd)?true:false;
			instance.isRightSlide = (instance.point>instance.rightEnd)?true:false;
			//console.log('isLeftSlide='+instance.isLeftSlide+':isRightSlide='+instance.isRightSlide);
			instance.my_left.className=(instance.isLeftSlide)?'':instance.my_endClass;
			instance.my_right.className=(instance.isRightSlide)?'':instance.my_endClass;
				
		}
	},20);
}
// ▲LockUP追加箇所 -------------------------------------------






var host = "re.veritrans.co.jp";

function sbiRecommend(type, query, charset, target_id) {
  if(!navigator.userAgent.match(/Mozilla\/4\.0 \(compatible; MSIE 5\.\d*; (Windows|MSN|AOL)/)){
    charset = "UTF-8";
  }
  if(!target_id){
    target_id = type;
  }
  var q = query == "" ? "" : query + "&";
  var url = location.protocol + "//" + host + "/recommend/" + type + "/?" + q + "target_id=" + target_id + "&charset=" + charset;

  var func = function(){
    var script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.setAttribute('charset', charset);
    script.setAttribute('src', url);
    var target = document.getElementById(target_id);
    target.appendChild(script);
  }

  if(window.addEventListener){
    window.addEventListener('load', func, false);
  }else if(window.attachEvent){
    window.attachEvent('onload', func);
  }else{
    window.onload = func;
  }
}


function setCtr(item_code,type,link,k){
  var item_url = link.href;
  var img = new Image(0,0);
  var r_num = Math.floor(Math.random() * 10000); // キャッシュ対策用ランダム数字
  img.src = location.protocol + "//" + host + "/recommend/set_ctr/?item_code=" + item_code  +"&t=" + type + "&k=" + k + "&r=" + r_num;
  img.onload = function(){
    location.href = item_url;
  }
  img.onerror = function(){
    location.href = item_url;
  }
}


function getParam(param) {
  var params = location.search;
  if(!params) return false;
  params     = params.substring(1);

  var pairs  = params.split("&");
  var key    = new Array();

  for (i = 0; i < pairs.length; i++) {
    pair          = pairs[i].split("=");
    key[pair[0]]  = pair[1];
  }
  return key[param];
}


function sbiProp(uid, query, k) {

 params = [];
 var tmp_params = query.split("&");
 for(i=0; i<tmp_params.length; i++){
   params.push( "prop[" + tmp_params[i].split("=")[0] + "]=" + tmp_params[i].split("=")[1]);
 }
 var q = params.join("&");

 k_params = k.split("&");
 for(i=0; i<k_params.length; i++){
   var img = new Image(0,0);
   img.src = location.protocol + "//" + host + "/prop/add/?uid=" + uid + "&k=" + k_params[i]  +  "&" +  q;
 }
}