﻿/*
 * Rich JavaScript PhotoViewer.js, version 1.0
 * Copyright (c) 2009 Lee Won-Gyoon <mail.kido@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * For details, see the RichScript web site: http://www.richScript.net/
 * 
*******************************************************************************/

function GalleryViewer (_instanceName) {
	this.instanceName = _instanceName;
	this.vars = {
		photoW : 270
		, photoH : 246
		, textW : 270
		, textH : 42
		, sideW : 276
		, sideH : 252
		, mainW : 290
		, mainH : 299
		, currentIndex : 0
	};
	this.ids = {
		leftArea : this.instanceName + "-leftArea"
		, mainArea : this.instanceName + "-mainArea"
		, rightArea : this.instanceName + "-rightArea"
	};
	this.data = [];
	
	this.scrollToPrev = function() {
		if (this.vars.currentIndex>=0) {
			this.vars.currentIndex--;
			this.scroll();
		} else {
			//alert("");
		}
	};
	
	this.scrollToNext = function() {
		if (this.vars.currentIndex<this.data.length-2) {
			this.vars.currentIndex++;
			this.scroll();
		} else {
			//alert("");
		}
	};
	
	this.scroll = function() {
		$(this.ids.leftArea).moveTo(this.vars.photoW*-1*this.vars.currentIndex,null);
		$(this.ids.mainArea).moveTo(this.vars.photoW*-1*(this.vars.currentIndex+1),null);
		$(this.ids.rightArea).moveTo(this.vars.photoW*-1*(this.vars.currentIndex+2),null);
	};

	this.push = function(_idx, _photoSrc, _bigSrc, _textSrc, _pwid, _phei) {
	  
	    this.data.push({
	        idx: _idx
			, photo: _photoSrc
			, big: _bigSrc
			, text: _textSrc
			, picw: _pwid
			, pich: _phei
	    });
	};
	

	

	this.getHTML = function() {
		 var s='';
	   
	    s += '<div class="gallery_box">\n';
		s += '	<div class="gallery_view">\n';	
		s += '		<a id="link" href=javascript:popup("'+this.data[0].idx+'","'+this.data[0].picw+'","'+this.data[0].pich+'")><img src="'+this.data[0].big+'" alt="" id="gallery_view"><a><br>\n';
		s += '	</div>\n';
		s += '</div>\n';
		s += '<p class="gallery_title" id="gallery_title">'+this.data[0].text+'</p>\n';
		s += '<div class="h_space10"><!-- Space --></div>\n';
		s += '<ul class="gallery_list">\n';

		s += '	<li class="list"><img src="'+this.data[0].photo+'" alt="" class="cursor" name="'+this.data[0].big+'"  onclick=\'galleryView(this,"'+this.data[0].idx+'","'+this.data[0].text+'","'+this.data[0].picw+'","'+this.data[0].pich+'")\'><br></li>\n';
		try{
			s += '	<li class="list"><img src="'+this.data[1].photo+'" alt="" class="cursor" name="'+this.data[1].big+'" onclick=\'galleryView(this,"'+this.data[1].idx+'","'+this.data[1].text+'","'+this.data[1].picw+'","'+this.data[1].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try {
			s += '	<li class="list"><img src="'+this.data[2].photo+'" alt="" class="cursor" name="'+this.data[2].big+'" onclick=\'galleryView(this,"'+this.data[2].idx+'","'+this.data[2].text+'","'+this.data[2].picw+'","'+this.data[2].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list"><img src="' + this.data[3].photo + '" alt="" class="cursor" name="' + this.data[3].big + '" onclick=\'galleryView(this,"' + this.data[3].idx + '","' + this.data[3].text + '","'+this.data[3].picw+'","'+this.data[3].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list_end"><img src="' + this.data[4].photo + '" alt="" class="cursor" name="' + this.data[4].big + '" onclick=\'galleryView(this,"' + this.data[4].idx + '","' + this.data[4].text + '","'+this.data[4].picw+'","'+this.data[4].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list_end"><br></li>\n';
		}
		s += '</ul>\n';
		s += '<ul class="gallery_list">\n';
		try {
		    s += '	<li class="list"><img src="' + this.data[5].photo + '" alt="" class="cursor" name="' + this.data[5].big + '" onclick=\'galleryView(this,"' + this.data[5].idx + '","' + this.data[5].text + '","'+this.data[5].picw+'","'+this.data[5].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list"><img src="' + this.data[6].photo + '" alt="" class="cursor" name="' + this.data[6].big + '" onclick=\'galleryView(this,"' + this.data[6].idx + '","' + this.data[6].text + '","'+this.data[6].picw+'","'+this.data[6].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list"><img src="' + this.data[7].photo + '" alt="" class="cursor" name="' + this.data[7].big + '" onclick=\'galleryView(this,"' + this.data[7].idx + '","' + this.data[7].text + '","'+this.data[7].picw+'","'+this.data[7].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list"><img src="' + this.data[8].photo + '" alt="" class="cursor" name="' + this.data[8].big + '" onclick=\'galleryView(this,"' + this.data[8].idx + '","' + this.data[8].text + '","'+this.data[8].picw+'","'+this.data[8].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list"><br></li>\n';
		}
		try{
		    s += '	<li class="list_end"><img src="' + this.data[9].photo + '" alt="" class="cursor" name="' + this.data[9].big + '" onclick=\'galleryView(this,"' + this.data[9].idx + '","' + this.data[9].text + '","'+this.data[9].picw+'","'+this.data[9].pich+'")\'><br></li>\n';
		}catch (e) {
			s += '	<li class="list_end"><br></li>\n';
		}
		s += '</ul>\n';
      // alert(s);
       return s;
	};


	
	this.print = function() {
		document.write(this.getHTML());
	};

	
	
	this.initialize = function() {
	};
};