//<![CDATA[
// 공실  스크롤링 
function scrolling(objId,sec1,sec2,speed,height){
  this.objId=objId;
  this.sec1=sec1;
  this.sec2=sec2;
  this.speed=speed;
  this.height=height;
  this.h=0;
  this.div=$(this.objId);
  this.htmltxt=this.div.innerHTML;
  this.div.innerHTML=this.htmltxt+this.htmltxt;
  this.div.isover=false;
  this.div.onmouseover=function(){this.isover=true;}
  this.div.onmouseout=function(){this.isover=false;}
  var self=this;
  this.div.scrollTop=0;
  window.setTimeout(function(){self.play()},this.sec1);
}
scrolling.prototype={
  play:function(){
    var self=this;
    if(!this.div.isover){
      this.div.scrollTop+=this.speed;
      if(this.div.scrollTop>this.div.scrollHeight/2){
        this.div.scrollTop=0;
      }else{
        this.h+=this.speed;
        if(this.h>=this.height){
          if(this.h>this.height|| this.div.scrollTop%this.height !=0){
            this.div.scrollTop-=this.h%this.height;
          }
          this.h=0;
          window.setTimeout(function(){self.play()},this.sec1);
          return;
        }
      }
    }
    window.setTimeout(function(){self.play()},this.sec2);
  },
  prev:function(){
    if(this.div.scrollTop == 0)
    this.div.scrollTop = this.div.scrollHeight/2;
    this.div.scrollTop -= this.height;
  },
  next:function(){
    if(this.div.scrollTop ==  this.div.scrollHeight/2)
    this.div.scrollTop =0;
    this.div.scrollTop += this.height;
  }
};
//일반 검색폼 탭메뉴제어
function mainSearch(select){
	$('psch1').hide();
	$('psch2').hide();
	if ($('psch3')) {
		$('psch3').hide();
	}
	$('psch'+select).show();
	$('schTab1').removeClassName('on');
	$('schTab2').removeClassName('on');
	if($('psch3')){
		$('schTab3').removeClassName('on');
	} 
	$('schTab'+select).addClassName('on');
	
}	

//웨딩 검색폼 탭메뉴제어	
function mainSearchWedding(select){
	
	$('psch1').hide()
	$('psch2').hide()
	$('psch3').hide()
	$('psch'+select).show()
	
	$('schTab1').removeClassName('on')
	$('schTab2').removeClassName('on')
	$('schTab3').removeClassName('on')
	$('schTab'+select).addClassName('on')
}		

//세부탭메뉴 스타일제거
function partnerDescStyleSet(id){
	try{
		$A($(id).getElementsByTagName("li")).each(function(e){
			$(e.id).removeClassName('on')
		})
	}catch(e){
		alert(e.meassage)
	}
	
}

//검색폼 submit 
function searchPartnerFormChk(){
	if($('search_partner[partner_type]').value.blank() && $('search_partner[gugun]').value.blank() && $('search_partner[partner_name]').value.blank()){
		alert("파트너 카테고리/지역/업체명 중에  검색조건을 하나 이상 사용하셔야 합니다.");
		return false;
	}
	return true;
}
function searchProductFormChk(){
	if(!$('search_product[price_from]').value.blank() && !$('search_product[price_to]').value.blank()){
	 if(Number($('search_product[price_from]').value.gsub(/[^\d]/,'')) > Number($('search_product[price_to]').value.gsub(/[^\d]/,''))){
			alert("가격검색 시작값이 종료값보다 큽니다.");
			return false;
		}
	}
	if($('search_product[partner_type]').value.blank() && $('search_product[sido]').value.blank() && $('search_product[product_name]').value.blank()&& $('search_product[price_from]').value.blank() ){
		alert("파트너 카테고리/지역/상품명/가격대  중에  검색조건을 하나 이상 사용하셔야 합니다.");
		return false;
	}
	return true;
}

function searchRoomFormChk(){
	return true;
}


//사진보기
_photo_win = false;
function open_to_photoView(ajax_url, default_image) {
	if(_photo_win) {
		alert('사진보기 창을 열고 있습니다. \n\n잠시만 기다리세요.');
		return false;
	}
	layer_id = 'photo_win'
	scroll_to_top();
	var photoView_reset = function() {
		current_photo = 0;
		total_photo = 0;
		photo_list = null;
		photo_obj = null;
		_photo_win = false;
		return true;
	}
	_photo_win = new Window(layer_id, {width: 840, height: 840, layout: 'empty'} );
	_photo_win.setDestroyOnClose();
	_photo_win.setCloseCallback(photoView_reset);
	_photo_win.setAjaxContent(ajax_url, {method: 'get', parameters: {file_name: default_image}, asynchronous: true, evalScripts: true});
	_photo_win._center();
	_photo_win.setLocation(10, parseFloat(_photo_win.element.style.left));
}


current_photo = 0;
total_photo = 0;
photo_list = null;
photo_obj = null;
//사진보기 정보 세팅
function set_photo_info() {
	if(!photo_list) {
		photo_list = $$('a.thumbnail');
		total_photo = photo_list.length;
	}
	if(!photo_obj) photo_obj = $('photo_detail');
}
function reset_photo_info() {
	current_photo = 0;
	photo_list = null;	
}

//사진보기 - 다음
function photo_next() {
	set_photo_info();
	
	//다음 이미지
	if(total_photo - 1 > current_photo) {
		var img_url = photo_list[++current_photo].getAttribute('href');
		photo_obj.setAttribute('src', img_url);
	}
	//다음 페이지
	else {
		$('nxt_page_btn').onclick();
	}
	
}

//사진보기 - 이전
function photo_prev() {
	set_photo_info();
	
	//이전 이미지
	if(current_photo > 0) {
		var img_url = photo_list[--current_photo].getAttribute('href');
		photo_obj.setAttribute('src', img_url);
	}
	//이전 페이지
	else {
		$('pre_page_btn').onclick();
	}
}


//사진보기 - 사진 크게 보기
function set_photo(image_url, order) {
	img = $('photo_detail');
	img.setAttribute('src', image_url);
	current_photo = order;
}

//사진보기 - 사진 앨범
function set_photo_album(request_url, this_obj) {
	var album = $$('#PhotoAlbumBox a');
	for(i=0; album.length > i; i++) {
		if(album[i] == this_obj) this_obj.addClassName('on');
		else album[i].removeClassName('on');
	}
	ajax_call(request_url);
}

//사진보기 - 다음 사진앨범
function photo_album_next() {
	var album = $$('#PhotoAlbumBox a');
	var album_size = album.length;
	var current_album = 0;
	for(i=0; album_size > i; i++) {
		if(album[i].hasClassName('on')) current_album = i;
	}
	if(current_album < album_size - 1) {
		album[current_album + 1].onclick();
	}
	else {
		alert('마지막 사진입니다.');
	}
}

//사진보기 - 이전 사진앨범
function photo_album_prev() {
	var album = $$('#PhotoAlbumBox a');
	var album_size = album.length;
	var current_album = 0;
	for(i=0; album_size > i; i++) {
		if(album[i].hasClassName('on')) current_album = i;
	}
	if(current_album > 0) {
		album[current_album - 1].onclick();
	}
	else {
		alert('첫 사진입니다.');
	}
}



//이미지교체 
function  photoChangeView(path){
	$('priviewImage').src = path 
}
//]]>	
