
var topImageRealWidth = 1250;
var topImageRealHeight = 500;
var interval = 10000;
var image1_index = 0;
var image1_cnt = 0;
var fadeInTerm = 1000;
var cont_action = getContAction();
var popup1_flag = false;
var popup_flag = false;
$(function(){
    if(isIE6()) {
         $("html , body").css('overflow' , 'hidden');
         // $('div#top_arrow ul').css("width" , "");
    // if(isIE6()) {
         $('div#top_arrow ul').css("width" , ($(window).width() + 12).toString() + 'px');
    // }
    }
    $("#slideshowbottom").simplyScroll({
        autoMode: 'loop' ,
        direction: 'right' ,
        // speed: 1, //No of pixels per frame
        frameRate : 30 ,
        pauseOnHover: false
    });
    image1_cnt = countImage1();
    DD_belatedPNG.fix('#top_arrow img');
    $('#main_top').positionFixed();
    $(window).bind('resize' , function(){
        fixTopImage();
        fixBottomSlide();
    });
    $('a.nextImage').click(function(){
        changeSlide1('next' , 'fast');
        return false;
    });
    $('a.beforeImage').hover(function(){
        $(this).find('img').attr('src' , '/images/index/img_arrow_la.png');
    } , function(){
        $(this).find('img').attr('src' , '/images/index/img_arrow_l.png');
    });
    $('a.nextImage').hover(function(){
        $(this).find('img').attr('src' , '/images/index/img_arrow_ra.png');
    } , function(){
        $(this).find('img').attr('src' , '/images/index/img_arrow_r.png');
    });
    $('a.beforeImage').click(function(){
        changeSlide1('pre', 'fast');
        return false;
    });
    setInterval(function(){
        changeSlide1('next', 'fadeIn');
    } , interval);
    changeSlide1('next', 'fadeIn');
    // スライド、一覧のボタン切り替え
    if(cont_action.cont == 'default') {

    } else if(cont_action.cont == 'lists') {
        $('img#top_kirikae_button1').attr('src' ,'/images/index/img_head_slide.gif' );
        $('img#top_kirikae_button2').attr('src' ,'/images/index/img_head_list_a.gif' );
    }
    fixTopImage();
    fixBottomSlide();
});
$(window).load(function(){
    // $('#popup1 img, #popup2 img').ifixpng();
    // 画像等読み込み後の処理
    // menuオープン
    $("div.global_menu").slideDown("fast");
    panel_status.menu = 1;
    // 検索パネルオープン
    $("div.slide_search_body").slideDown("fast");
    panel_status.body = 1;
    var init_open = true;
    timer = setTimeout(function(){
        // menuオープン
        $("div.global_menu").slideUp("fast");
        panel_status.menu = 0;
        // 検索パネルオープン
        $("div.slide_search_body").slideUp("fast");
        panel_status.body = 0;
        init_open = false;
    } , 3000);
    $('div.slide_search_body , div.global_menu').mouseover(function(){
        if(init_open) {
            clearTimeout(timer);
        }
    });

    $('img.top_slide_bottom').hover(function(){
        var new_src = $(this).attr('src').replace('_a.png' , '.png');
        $(this).attr('src' , new_src);
        popup2_flag = true;
        $('#popup2').show();
    } , function(){
        var new_src = $(this).attr('src').replace('.png' , '_a.png');
        $(this).attr('src' , new_src);
        popup2_flag = false;
        $('#popup2').hide();
    });
    $('img.top_slide_bottom').mousemove(function(event){
        moveIconMouse(event , 'popup2');
    });
    $('#top_image img').hover(function(){
        $('#popup1').show();
    } , function(){
        $('#popup1').hide();
    });
    $('#top_image img').mousemove(function(event){
        moveIconMouse(event , 'popup1');
    });
});


var countImage1 = function(){
    var count = 0;
    $('#top_image img').each(function(){
        var this_image_id = $(this).attr('id');
        if(this_image_id.match(/slide\_image([0-9]{1,2})/)) {
            count++;
        }
    });
    return count;
};
var changeSlide1 = function(mode , change) {
    if(cont_action.cont != 'default') {
        return true;
    }
    if(mode != 'next' && mode != 'pre') {
        return false;
    }
    if(mode == 'next') {
        image1_index++;
    } else {
        image1_index--;
    }
    var $canvas = $('#slide_canvas');
    var $new_image = $('#slide_image' + image1_index.toString());
    if(!$new_image.size()) {
        if(mode == 'next') {
            image1_index = 1;
        } else {
            image1_index = image1_cnt;
        }
        $new_image = $('#slide_image' + image1_index.toString());
    }
    if(change == 'fadeIn') {
        $canvas.fadeOut(fadeInTerm , function(){
            $canvas.attr('src' , $new_image.attr('src')).fadeIn(fadeInTerm);
        });
    } else if (change == 'fast') {
        $canvas.fadeOut(50 , function(){
            $canvas.attr('src' , $new_image.attr('src')).fadeIn(50);
        });

    }
    $canvas.attr('alt' , $new_image.attr('alt')).parent().attr('href' , $new_image.parent().attr('href'));
    return true;
};

var fixBottomSlide = function() {
    var slide_width = $(window).width() - 250;
    if(isIE6()) {
        slide_width += 10;
    }
    $('.simply-scroll , .simply-scroll , .simply-scroll-clip').css('width' , slide_width + 'px');
};

var fixTopImage = function() {
    var image_width = $(window).width();
    if(image_width < topImageRealWidth) {
        $('#slide_canvas').css('width' , '');
    } else {
        $('#slide_canvas').css('width' , '100%');
    }
};
var moveIconMouse = function(e , image_id){
	// マウスの座標処理
	var x, y, obj , offsetX= 5, offsetY= 10 * (-1);
	// Opera,Safari
	if(document.all && document.getElementById && (document.compatMode=='CSS1Compat')) {
		x=event.clientX+document.documentElement.scrollLeft;
		y=event.clientY+document.documentElement.scrollTop;
	// IE
	} else if(document.all){
		x=event.x+document.body.scrollLeft;
		y=event.y+document.body.scrollTop;
	// Mozilla,Camino
	} else if(document.getElementById){
		x=e.pageX;
		y=e.pageY;
	}
	if(document.getElementById(image_id)){
		document.getElementById(image_id).style.left=x+offsetX+'px';
		document.getElementById(image_id).style.top=y+offsetY+'px';
	}
}

