﻿var minPages = 1
var maxPages = 6

var Button = Class.create();
Button.prototype = {
	initialize: function(options){
		this.options = Object.extend({
			properties : {
				href : "",
				id : "",
				action : "",
				linkBind : "",
				pageNumber : "",
				updateContainerID : "",
				imageNo: "",
				altTag: ""
			}
		}, options || {});
	},
	
	setupButton : function(){
		this.setHref();
		this.buttonClick();
	},
	
	setHref : function(){
		this.options.properties.href="javascript:void(0);";
		$(this.options.properties.id).href="javascript:void(0);";
	},
	
	buttonClick : function(){	
		if(this.options.properties.action == "image"){
			this.options.properties.linkBind = this.showImageContent.bindAsEventListener(this);
			Event.observe(this.options.properties.id, 'click', this.options.properties.linkBind);
		}else{		
			this.options.properties.linkBind = this.showContent.bindAsEventListener(this);
			Event.observe(this.options.properties.id, 'click', this.options.properties.linkBind);
		}
	},
	
	showContent : function(){
		var ajaxDisplay, i;
		var buttonObject = this;
		new Effect.Fade($("story_Content"), {duration: 0.5, afterFinish:function(){ajax_LoadPatentPanel(buttonObject, "page"); new Effect.Appear($("story_Content"), {delay:0.1, duration: 1.0, from: 0.0, to: 1.0});}});
	},
	
	showImageContent : function(){
		var ajaxDisplay, i;
		var buttonObject = this;
		new Effect.Fade($("story_Content_MainImage"), {duration: 0.5, afterFinish:function(){ajax_LoadPatentPanel(buttonObject, "image"); new Effect.Appear($("story_Content_MainImage"), {delay:0.1, duration: 1.0, from: 0.0, to: 1.0});}});
	}
};

function getPageNo(direction, currentPageNo){
	if(direction =="prev"){
		if(minPages > (currentPageNo - 1)){
			newPageNo = maxPages;
		}else{
			newPageNo = currentPageNo - 1;
		}
	}else{
		if(maxPages < (currentPageNo + 1)){
			newPageNo = minPages;
		}else{
			newPageNo = currentPageNo + 1;
		}
	}
	return newPageNo;
}

function ajax_LoadPatentPanel(buttonObject, actionType){
	var data, ajaxResults, url, prevPageNo;
	if(actionType == "page"){
		pageNo = buttonObject.options.properties.pageNumber;
		data = "pageNumber=" + pageNo + "&ajaxUsed=true";
	}else if(actionType == "image"){
		pageNo = buttonObject.options.properties.pageNumber;
		imageNo = buttonObject.options.properties.imageNo;
		altTag = buttonObject.options.properties.altTag;
		data = "pageNumber=" + pageNo + "&ajaxUsed=true&imageNumber=" + imageNo + "&altTagValue=" + altTag;	
	}
	url = "/dc26/story/story_ajax.asp";
	ajaxResults = new Ajax.Updater({success: buttonObject.options.properties.updateContainerID, failure:reportError}, url, {method: 'post', parameters: data, evalScripts: true});
}


function contentPanelAppear(){
	if($("story_Content")){
		new Effect.Appear($("story_Content"), {duration: 1.0, from: 0.0, to: 1.0});
	}else{
		setTimeout("contentPanelAppear()",100);	
	}
}

function reportError(request){
	alert("User - Please ignore. Developer - Error with Ajax, please investigate.");
}

function imageHandler(pageId){
	var dyBoxObjectsArray = new Array();

	if ($("story_Content_1")) {
	    if ($("story_Content_1_Image1")) {
	        story1Image1Button = new Button({
	            properties: { href: "javascript:void(0);", id: "story_Content_1_Image1", action: "image", pageNumber: 1, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "製品の設計図" }
	        });
	        story1Image1Button.setupButton();
	    }
	    if ($("story_Content_1_Image2")) {
	        dyBoxLink = new DyBoxObject({
	            compulsory: { linkType: "image", name: "story_Content_1_Image2", originalLinkID: "story_Content_1_Image2", mediaType: "video" },
	            videoDetails: { videoLocation: mediaServerLocation + "/swf/campaigns/JP26/assets/main/main_0_2.flv", videoType: "flv" },
	            imageLink: { imageSRC: "/dc26/images/story/story1_Image2_Small_Video.jpg", imageALT: "DC26の開発", linkText: "", rolloverAvailable: "true"
	            },
	            containerDimensions: { height: 265, width: 290 }
	        });
	        dyBoxObjectsArray[0] = dyBoxLink;
	        setUpDyBoxLinks(dyBoxObjectsArray);
	    }
	}
	if ($("story_Content_2")) {
	    if ($("story_Content_2_Image1")) {
	        story2Image1Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_2_Image1", action: "image", pageNumber: 2, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "製品テスト" }
	        });
	        story2Image1Button.setupButton();
	    }
	    if ($("story_Content_2_Image2")) {
	        dyBoxLink = new DyBoxObject({
	            compulsory: { linkType: "image", name: "story_Content_2_Image2", originalLinkID: "story_Content_2_Image2", mediaType: "video" },
	            videoDetails: { videoLocation: mediaServerLocation + "/swf/campaigns/JP26/assets/main/main_1_2.flv", videoType: "flv" },
	            imageLink: { imageSRC: "/dc26/images/story/story2_Image2_Small_Video.jpg", imageALT: "DC26のテスト", linkText: "", rolloverAvailable: "true"
	            },
	            containerDimensions: { height: 265, width: 290 }
	        });
	        dyBoxObjectsArray[0] = dyBoxLink;
	        setUpDyBoxLinks(dyBoxObjectsArray);
	    }
	}
	if($("story_Content_3")){
	    if ($("story_Content_3_Image1")) {
	        story3Image1Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_3_Image1", action: "image", pageNumber: 3, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "DC26のパーツ（部品)" }
	        });
	        story3Image1Button.setupButton();
	    }
	    if ($("story_Content_3_Image2")) {
	        dyBoxLink = new DyBoxObject({
	            compulsory: { linkType: "image", name: "story_Content_3_Image2", originalLinkID: "story_Content_3_Image2", mediaType: "video" },
	            videoDetails: { videoLocation: mediaServerLocation + "/swf/campaigns/JP26/assets/main/main_2_2.flv", videoType: "flv" },
	            imageLink: { imageSRC: "/dc26/images/story/story3_Image2_Small_Video.jpg", imageALT: "困難な挑戦", linkText: "", rolloverAvailable: "true"
	            },
	            containerDimensions: { height: 265, width: 290 }
	        });
	        dyBoxObjectsArray[0] = dyBoxLink;
	        setUpDyBoxLinks(dyBoxObjectsArray);
	    }
	}
	if ($("story_Content_4")) {
	    if ($("story_Content_4_Image1")) {
	        story4Image1Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_4_Image1", action: "image", pageNumber: 4, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "ダイソンでいちばん小さな掃除機DC26" }
	        });
	        story4Image1Button.setupButton();
	    }
	    if ($("story_Content_4_Image2")) {
	        story4Image2Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_4_Image2", action: "image", pageNumber: 4, updateContainerID: "story_Content_MainImage", imageNo: 2, altTag: "DC26サイドショット" }
	        });
	        story4Image2Button.setupButton();
	    }
	    if ($("story_Content_4_Image3")) {
	        story4Image3Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_4_Image3", action: "image", pageNumber: 4, updateContainerID: "story_Content_MainImage", imageNo: 3, altTag: "Root Cyclone™ の中" }
	        });
	        story4Image3Button.setupButton();
	    }
	}
	if ($("story_Content_5")) {
	    if ($("story_Content_5_Image1")) {
	        story5Image1Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_5_Image1", action: "image", pageNumber: 5, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "フロアツール" }
	        });
	        story5Image1Button.setupButton();
	    }
	    if ($("story_Content_5_Image2")) {
	        story5Image2Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_5_Image2", action: "image", pageNumber: 5, updateContainerID: "story_Content_MainImage", imageNo: 2, altTag: "ヘッドのサイドショット" }
	        });
	        story5Image2Button.setupButton();
	    }
	    if ($("story_Content_5_Image3")) {
	        dyBoxLink = new DyBoxObject({
	            compulsory: { linkType: "image", name: "story_Content_5_Image3", originalLinkID: "story_Content_5_Image3", mediaType: "video" },
	            videoDetails: { videoLocation: mediaServerLocation + "/swf/campaigns/JP26/assets/main/main_4_3.flv", videoType: "flv" },
	            imageLink: { imageSRC: "/dc26/images/story/story5_Image3_Small_Video.jpg", imageALT: "ヘッドの開発", linkText: "", rolloverAvailable: "true"
	            },
	            containerDimensions: { height: 265, width: 290 }
	        });
	        dyBoxObjectsArray[0] = dyBoxLink;
	        setUpDyBoxLinks(dyBoxObjectsArray);
	    }
	}
	if($("story_Content_6") && $("story_Content_6_Image1")){
	    if ($("story_Content_6_Image1")) {
	        story6Image1Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_6_Image1", action: "image", pageNumber: 6, updateContainerID: "story_Content_MainImage", imageNo: 1, altTag: "試作品" }
	        });
	        story6Image1Button.setupButton();
	    }
	    if ($("story_Content_6_Image2")) {
	        story6Image2Button = new Button({
	        properties: { href: "javascript:void(0);", id: "story_Content_6_Image2", action: "image", pageNumber: 6, updateContainerID: "story_Content_MainImage", imageNo: 2, altTag: "初期の試作品" }
	        });
	        story6Image2Button.setupButton();
	    }
	    if ($("story_Content_6_Image3")) {
	        dyBoxLink = new DyBoxObject({
	            compulsory: { linkType: "image", name: "story_Content_6_Image3", originalLinkID: "story_Content_6_Image3", mediaType: "video" },
	            videoDetails: { videoLocation: mediaServerLocation + "/swf/campaigns/JP26/assets/main/main_5_3.flv", videoType: "flv" },
	            imageLink: { imageSRC: "/dc26/images/story/story6_Image3_Small_Video.jpg", imageALT: "試作品づくり", linkText: "", rolloverAvailable: "true"
	            },
	            containerDimensions: { height: 265, width: 290 }
	        });
	        dyBoxObjectsArray[0] = dyBoxLink;
	        setUpDyBoxLinks(dyBoxObjectsArray);
	    }
	}
}

function attachStartListener(pageId){
	if($("story_Nav")){
		storyButton1 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav1", action : "open", pageNumber : 1, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton1.setupButton();
		
		storyButton2 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav2", action : "open", pageNumber : 2, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton2.setupButton();
		
		storyButton3 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav3", action : "open", pageNumber : 3, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton3.setupButton();
		
		storyButton4 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav4", action : "open", pageNumber : 4, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton4.setupButton();
		
		storyButton5 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav5", action : "open", pageNumber : 5, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton5.setupButton();
		
		storyButton6 = new Button({
			properties : {href : "javascript:void(0);", id : "story_Nav6", action : "open", pageNumber : 6, updateContainerID : "story_Items", imageNo : 1}
		});	
		storyButton6.setupButton();
	}
	if($("story_Prev")){
		pageNumber = getPageNo("prev", pageId);
		prevButton = new Button({
			properties : {href : "javascript:void(0);", id : "story_Prev", action : "prev", pageNumber : pageNumber, updateContainerID : "story_Items"}
		});	
		prevButton.setupButton();
	}  
	if($("story_Next")){	
		pageNumber = getPageNo("next", pageId);
		nextButton = new Button({
			properties : {href : "javascript:void(0);", id : "story_Next", action : "next", pageNumber : pageNumber, updateContainerID : "story_Items"}
		});	
		nextButton.setupButton();
	}
	if($("story_CloseBtn")){
		closeButton = new Button({
			properties : {href : "javascript:void(0);", id : "story_CloseBtn", action : "close", pageNumber : 0, updateContainerID : "story_Items"}
		});	
		closeButton.setupButton();
	}
}

function loadFlashVideo(){
	var so = new SWFObject(mediaServerLocation + "/swf/campaigns/JP26/loader.swf", "letterboxID", "910", "440", "9.0.16", "#000000");
	so.addParam("allowScriptAccess", "always"); 
	so.addParam("menu", "false");
	so.addVariable("file", "story");
	so.write("story");
}

Event.observe(window, "load", function(){loadFlashVideo(); if($("letterboxID")){var storyContainer = $("letterboxID"); storyContainer.className = "flashContent";}});