/**
 * @conpyright Artlist, Inc.
 * @date 2010.09.30
 */
var NaviSetting = {
	current: 0,
	navs: {
		'ja': {
			 0: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 1: {activation: true,  href: 'http://www.thedog-club.com/character/',  target: '_blank', html:'THE DOG', id: 'naviTheDog', className: 'site-navi'},
			 2: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 3: {activation: true,  href: 'http://www.thecat-club.com/japanese.html',  target: '_blank', html:'THE CAT', id: 'naviTheCat', className: 'site-navi'},
			 4: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 5: {activation: true,  href: 'http://www.thepig-club.com/japanese.html',  target: '_blank', html:'THE PIG', id: 'naviThePig', className: 'site-navi'},
			 6: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 7: {activation: true,  href: 'http://www.artliststore.com/', target: '_blank', html:'Artlist Store', id: 'naviArtlistStore', className: 'site-navi'},
			 8: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 9: {activation: true,  href: 'http://www.dog-image.com/', target: '_blank', html:'DOG Image', id: 'naviDogImage', className: 'site-navi'},
			10: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'}
		},
		'en': {
			 0: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 1: {activation: true,  href: 'http://www.thedog-clubs.com/home.html',  target: '_blank', html:'THE DOG', id: 'naviTheDog', className: 'site-navi'},
			 2: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 3: {activation: true,  href: 'http://www.thecat-club.com/english/',  target: '_blank', html:'THE CAT', id: 'naviTheCat', className: 'site-navi'},
			 4: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 5: {activation: true,  href: 'http://www.thepig-club.com/english/',  target: '_blank', html:'THE PIG', id: 'naviThePig', className: 'site-navi'},
			 6: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 7: {activation: true,  href: 'http://www.artliststore.com/', target: '_blank', html:'Artlist Store', id: 'naviArtlistStore', className: 'site-navi'},
			 8: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'},
			 9: {activation: true,  href: 'http://en.dog-image.com/', target: '_blank', html:'DOG Image', id: 'naviDogImage', className: 'site-navi'},
			10: {activation: false, href: '', target: '', html:'', id: '', className: 'site-navi'}
		}
	},
	pathPrefix: {
		'ja': './',
		'en': './../'
	},
	randomImages: [
		"commonsources/images/main_images/artlist001.png",
		"commonsources/images/main_images/artlist004.png",
		"commonsources/images/main_images/artlist008.png",
		"commonsources/images/main_images/artlist010.png"
	],
	getNavigationProperty: function(locale, key) {
		if (!this.navs[locale]) {
			locale = 'en';
		}
		for (var i in this.navs[locale]) {
			if (this.navs[locale][i].id == key) {
				return this.navs[locale][i];
			}
		}
		return null;
	},
	getPathPrefix: function(locale) {
		if (!this.navs[locale]) {
			return '/';
		}
		return this.pathPrefix[locale];
	}
}

var SlideSetting = {
	startingSlide: 0,
	easeIn: 'bounceout', 
	delay: 0,
	fx: 'cover',
	direction: 'down',
	speed: 1000, 
	timeout: 5000, 
	cssAfter: {},
	before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
		NaviSetting.current = $(nextSlideElement).attr('id').replace('slide', '');
	},
	after: function(currSlideElement, nextSlideElement, options, forwardFlag) {},
	pager: '#mainNavi', 
	pagerEvent: 'click', 
	pagerAnchorBuilder: function(index, DOMelement){
		var name = $(DOMelement).attr('name');
		if (!name) return '';
		var ns = NaviSetting.getNavigationProperty(Locale.getLocale(), name);
		var href = target = html = id = className = '';
		if (ns.activation) {
			href = ns.href;
			target = ns.target;
			target = (target == '' ? '' : ' target="' + target + '"');
			html = ns.html;
			id = ns.id;
			className = ns.className;
		} else {
			return '';
		}
		return '<li><a href="javascript: void(0)" id="' + id + '" class="sprite ' + className + '" ' + target + '><span class="text">' + html + '</span></a></li>';
	}
}

$(function() {
	jQuery.each($('.image'), function(i, val) {
		$(val).attr('id', 'slide' + i);
	});

	jQuery.each($('.random-image'), function(key, val) {
		var r = Math.floor(Math.random() * 3);
		var n = Math.floor(Math.random() * NaviSetting.randomImages.length);
		if(r == 2) {
			$(val).html('<img src="' + NaviSetting.getPathPrefix(Locale.getLocale()) + NaviSetting.randomImages[n] + '" width="938" height="394" alt="Image of artlist" />');
		} else {
			// jQuery doesn't have DOM operators in default
			document.getElementById('imageSet').removeChild(val);
		}
	});

	$('#contentFrame').click(function() {
		var option = NaviSetting.navs[Locale.getLocale()][NaviSetting.current];
		if (option.href != '') {
			window.open(option.href);
		}
		return '';
	});

	// Slide ID
	var slideId = $.getQueryParam('si');

	// Get number of slides
	var slideLength = $('.image').size();

	// Starting before slide of posted ID one
	var startingSlide = (slideId ? slideId : 0);
	if (startingSlide < 0) {
		// Set last slide id if startingSlide less than 0
		startingSlide = slideLength - 1;
	}
	SlideSetting.startingSlide = startingSlide;

	// Set delay if slide ID is defined
	//SlideSetting.delay = SlideSetting.timeout * (slideId ? -1 : 0);

	$('#imageSet').cycle(SlideSetting);

// Don't Wrok ? By HASHIKI
//	if( slideId == slideLength - 5 ) location.reload();
});

