/* myquery js */

var tabinavi_user = '';
var date=new Date();
date.setTime(date.getTime()+(7*24*60*60*1000));
setTabinaviUser();

function triViewCtrl(e){
$(e+' dt span').click(function(){
$(this).parent().next().toggle();
if($(this).text()=='▲'){$(this).text('▼');}
else{$(this).text('▲');}
});
$(e+' dt a').hover(
function(){
$(e+' dt span').css('display','none').css('z-index',0);
$(this).next().css('display','block').css('z-index',1);
},
function(){}
);
$(e+' dt div.camouflage').hover(
function(){
$(e+' dt span').css('display','none').css('z-index',0);
$(this).next().css('display','block').css('z-index',1);
},
function(){}
);
$(e).hover(
function(){},
function(){
$(e+' dt span').css('display','none').css('z-index',0);
}
);
}
function openedTriView(e){
$(e+' dt span').parent().next().toggle();
if($(e+' dt span').text()=='▲'){
$(e+' dt span').text('▼');
}else{
$(e+' dt span').text('▲');
}
}

function areaViewCtrl(e){
$(e+' dt a').click(function(){
$(this).parent().next().toggle();
if($(this).parent().next().css('display')=='none'){
$(this).removeClass('opened');
}else{
$(this).addClass('opened');
}
});
}
function openedAreaView(e){
$(e+' dt a').parent().next().toggle();
if($(e+' dt a').parent().next().css('display')=='none'){
$(e+' dt a').removeClass('opened');
}else{
$(e+' dt a').addClass('opened');
}
}


function setTabinaviUser(){
if($.cookie("tabinavikashiwazaki-onetime")){
tabinavi_user = $.cookie("tabinavikashiwazaki-onetime");
$.cookie("tabinavikashiwazaki-onetime",tabinavi_user,{expires:date,path: '/'});
}else{
var randstr = getRandomStr(24,'?_-!');
tabinavi_user = randstr;
$.cookie("tabinavikashiwazaki-onetime",tabinavi_user,{expires:date,path: '/'});
}
}

function getRandomStr(n, b){
b = b || '';
var a = 'abcdefghijklmnopqrstuvwxyz'
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ '0123456789'
+ b;
a = a.split('');
var s = '';
for (var i = 0; i < n; i++) {
s += a[Math.floor(Math.random() * a.length)];
}
return s;
};


$(function(){
$("#tops .tabs").rollgallery({
tab_ctrl: '#tops .tabctrl',
tab_more: '#tops .tabup',
tab_next: '#tops .tabdown',
output: true ,
outputlist: '#tops .output'
});
$(".tnm_gallery .tabs").rollgallery({
tab_ctrl: '.tnm_gallery .tab_ctrl',
tab_more: '.tnm_gallery .tabup',
tab_next: '.tnm_gallery .tabdown',
tab_view: 2,
start_view:1
});

if($('#infomation').size()>0){
var tabconfig = {acvive_class: 'active',start_view: 0,output: true,outputlist: '#infomation .list'};
var tabtarget = $('#infomation .tabs');
var tabviewnow = tabconfig.start_view;
tabtarget.children().eq(tabconfig.start_view).addClass(tabconfig.acvive_class);
if(tabconfig.output){
$(tabconfig.outputlist).children().toggle();
$(tabconfig.outputlist).children().eq(tabviewnow).toggle();
}
tabtarget.children().hover(
function(){
tabtarget.children().removeClass(tabconfig.acvive_class);
$(this).addClass(tabconfig.acvive_class);
$(tabconfig.outputlist).children().eq(tabviewnow).toggle();
tabviewnow = tabtarget.children().index(this);
$(tabconfig.outputlist).children().eq(tabviewnow).toggle();
},
function(){}
);
}

if($('.tnm_spot').size()>0){triViewCtrl('.tnm_spot');}
if($('.tnm_course').size()>0){triViewCtrl('.tnm_course');}
if($('.tnm_event').size()>0){triViewCtrl('.tnm_event');}
if($('.tnm_course2').size()>0){areaViewCtrl('.tnm_course2');}
if($('.tnm_event2').size()>0){areaViewCtrl('.tnm_event2');}

if($('#addBookmark').size()>0){
$('#addBookmark').click(function(){
$.ajax({
type: "GET",
url: "http://www.tabinavi-kashiwazaki.com/dbsystem/coursemaker/api.php",
data: {
"mode":"add",
"id":$('#spotId').val()
},
success: function(data){
if(data.result){
alert("候補リストに追加しました");
}else{
alert("このスポットは既にリストに登録されています");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
//alert(XMLHttpRequest+"\n"+textStatus+"\n"+errorThrown);
}
});
});
}

});

