//luluss11

var fadeT = 1500;
var eoq = 'easeOutQuart';
var eioq = 'easeInOutQuart';

var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iimgHone|ipod|ipad)/);


$(document).ready(function(){
	
	$('div#cover').fadeOut(fadeT, eioq);
	
	if(!$('section').hasClass('archives')){
		$('nav a').click(function(){
			var url = $(this).attr('href');
			$('div#cover').fadeIn(fadeT, eioq, function(){ window.location.href=url; });
			return false;
		});
	}else{
		$('nav#menu a').click(function(){
			var url = $(this).attr('href');
			$('div#cover').fadeIn(fadeT, eioq, function(){ window.location.href=url; });
			return false;
		});
	}
	
	if($('body').attr('id') == 'home'){
		jQuery(function($){
			$.supersized({
				slide_interval : 5000,
				transition_speed : 1000,
				performance : 1,
				slides:[
				
				//Slideshow Images
				{ image : './img/bg.jpg'},
				{ image : './img/home/LULUSS11_INTRO2.jpg'},
				{ image : './img/home/LULUSS11_INTRO5.jpg'}
				
			]});
		});
		
		var url = 'http://www.lulucheung.com.hk/blog/';
		$('#blognews').append('<h2></h2><h3></h3>');	
		$('#blognews').find("h2").load(url+" "+"span.first");
		$('#blognews').find("h3").load(url+" "+"a.first", function(){
		$('#blognews a').attr('target', '_blank');});

//////////////////////////////////////////////////////////////////////
	var     $zoom = $('#zoom'),
		$test4 = $('#test4'),
		$caption = $('div.caption'),
		$pause = $('#pause'),
		$resume = $('#resume'),
		$freeze = $('#freeze'),
		$stop = $('#stop'),
		$restart = $('#restart'),
		STOP = 1, RUN = 2, PAUSE = 3;
		status = 0;
	$zoom.crossSlide({
			fade: 1
			},
			[
			{
				src:  './img/bg.jpg',
				alt:  '',
				from: '50% 0% 1x',
				to:   '30% 0% 3x',
				time:1 
			}
			], function(idx, img, idxOut, imgOut) {
				if (idxOut == undefined) {
					$caption.text(img.alt).animate({ opacity: .7 })
				} else {
					$caption.animate({ opacity: 0 })
				}
			}
			);
/*
	$caption.show().css({ opacity: 0 })

	function state(state) {
		$pause.attr('disabled', state != RUN);
		$resume.attr('disabled', state != PAUSE);
		$freeze.attr('disabled', state == STOP);
		$stop.attr('disabled', state == STOP);

	}
	state(RUN);

	$pause.click(function() {
		$test3.crossSlidePause();
		state(PAUSE);
	});

	$resume.click(function() {
		$test3.crossSlideResume();
		state(RUN);
	})

	$freeze.click(function() {
		$test3.crossSlideFreeze();
		state(STOP);
	});

	$stop.click(function() {
		$test3.crossSlideStop();
		$caption.css({ opacity: 0 })
		state(STOP);
	});

	$restart.click(function() {
		$test3.crossSlideRestart();
		state(RUN);
	});
*/
//////////////////////////////////////////////////////////////////////	

	}else if($('body').attr('id') == 'collections'){
			
		var _current = 1;
		var _total;
		var currentPic;
		var imgW = 960;
		var imgH = 720;
		var imgS;
		var divW;
		var divH;
		var nextW;
		var nextH;
		
		var wW = $(window).width();
		var wH = $(window).height();
			
		
		var _t = 1500;
		var _trans = 'easeInOutQuart';
		
		//setTimeout(nextImage, 5000);
		// Gallery Navigation ---------------------------------------------------------------------//
		$('span.prev').click(function(){
			if(_current > 1){
				_current--;
			}else if(_current == 1){
				_current = _total;
			}
			$('div.collections img').eq(_current).fadeOut(_t, _trans);
			$('div.collections img').eq(_current-1).fadeIn(_t, _trans);
			updateData();
		});
		$('span.next, div.collections img').click(function(){
			nextImage();
		});
		
		
		function nextImage(){
			if(_current != _total){
				_current++;
			}else if(_current == _total){
				_current = 1;
			}
			$('div.collections img').eq(_current-2).fadeOut(_t, _trans);
			$('div.collections img').eq(_current-1).fadeIn(_t, _trans);
			updateData();
		}
		
		// ----------------------------------------------------------------------------------------//
		//alert("imgW : "+imgW+" / "+"imgH : "+imgH+" / "+"imgS : "+imgS+" / "+"divW : "+divW+" / "+"divH : "+divH+" / "+"wW : "+wW+" / "+"wH : "+wH);
		
		
		// auto resize gallery---------------------------------------------------------------------//
		
	
		
		function updateData(){
			currentPic = $('div.collections img').eq(_current-1);			
			_total = $('div.collections img').size();
			
			//update number
			$('span.current').text(_current);
			$('span.total').text(_total);
			
			imgW = currentPic.width();
			imgH = currentPic.height();
			imgS = imgH/imgW;
			
			
			resizeImg();
		}
		
		function resizeImg(){
			
			wW = $(window).width();
			wH = $(window).height();
			divW = $('div.collections').width()-270;
			divH = $('div.collections').height()-130;
			
			if(divH/imgS > divW){
				currentPic.width(divW);
				currentPic.height(divW*imgS);
			}
			
			if(divW*imgS > divH){
				currentPic.height(divH);
				currentPic.width(divH/imgS);
			}
			
			//resize aside width
			$('section.collections aside').width(wW-(currentPic.width()+25+25+15));
		}
		
		//init
		updateData();
		
		
		
		if ($.browser.webkit) {
		//	updateScaleT();
		}
		
		$(window).resize(function() {
			updateData();
		});
		$('body').mousemove(function() {
			//updateData();
		});
		$('body').click(function() {
			//updateData();
		});
		$('body').mousedown(function() {
			//updateData();
		});
		
		
		
		
		
	}else if($('body').attr('id') == 'archives'){
		jQuery(function($){
			$.supersized({
				slides:[
				
				//Slideshow Images
				{ image : '../img/bg/bg01.jpg'}
				
			]}); 
		});
	}else if($('body').attr('id') == 'runway'){
	//	$('span.prev').fadeTo(0, 0.3);
		// init window size
		//$('.video-js-box').offset({ top: 200, left: 400});
		/*$('span.prev').click(function(){*/
		$('ul.runway_2 li.video').click(function(){
			$(this).css('cursor','default');
			$('ul.runway_2 li.the_show').css('cursor','pointer');
			$(this).fadeTo(0, 1.0);
			$('ul.runway_2 li.the_show').fadeTo(0, 0.4);
			$('article.p1').fadeIn(700, eioq);
			$('article.p2').fadeOut(700, eioq);
			$('.video-js-box').show();
		});
		$('ul.runway_2 li.the_show').click(function(){
		/*$('span.next').click(function(){*/
			$('ul.runway_2 li.video').css('cursor','pointer');
			$(this).css('cursor','default');
			$('ul.runway_2 li.video').fadeTo(0, 0.4);
			$(this).fadeTo(0, 1.0);
			$('article.p1').fadeOut(700, eioq);
			$('.video-js-box').hide();
			$('article.p2').fadeIn(700, eioq);
			$('span.current').text('2');
		});
		
		jQuery(function($){
			$.supersized({
				slides:[
				//Slideshow Images
				{ image : '../img/bg/bg02.jpg'}
				
			]}); 
		});

	}else if($('body').attr('id') == 'designer'){
		$('span.prev').fadeTo(0, 0.3);
		
		$('span.prev').click(function(){
			$(this).css('cursor','default');
			$('span.next').css('cursor','pointer');
			$(this).fadeTo(0, 0.3);
			$('span.next').fadeTo(0, 1);
			$('article.p1').fadeIn(700, eioq);
			$('article.p2').fadeOut(700, eioq);
			
			$('span.current').text('1');
		});
		$('span.next').click(function(){
			$('span.prev').css('cursor','pointer');
			$(this).css('cursor','default');
			$('span.prev').fadeTo(0, 1);
			$(this).fadeTo(0, 0.3);
			$('article.p1').fadeOut(700, eioq);
			$('article.p2').fadeIn(700, eioq);
			
			$('span.current').text('2');
		});
		
		jQuery(function($){
			$.supersized({
				slides:[
				
				//Slideshow Images
				{ image : '../img/bg/bg01.jpg'}
				
			]}); 
		});

	}else if($('body').attr('id') == 'contact'){
		jQuery(function($){
			$.supersized({
				slides:[
				
				//Slideshow Images
				{ image : '../img/bg/bg01.jpg'}
				
			]}); 
		});
	}else if($('body').attr('id') == 'location'){
		jQuery(function($){
			$.supersized({
				slides:[
				
				//Slideshow Images
				{ image : '../img/bg/bg01.jpg'}
				
			]}); 
		});
	}
	
	//nav
	/*$('nav#menu li').mouseover(function(){
		$('nav#menu li').fadeTo(0, 0.5);
		$(this).stop(true, true).fadeTo(700, 1, 'easeOutQuart');
	});
	$('nav#menu ul').mouseout(function(){
		$('nav#menu li').fadeTo(700, 1, 'easeOutQuart');
	});*/
//	}// end function		
		
		//--------------------------------------------------------------------------------------------//
	//hide addressbar from iOS
	if ($.browser.webkit) {	addEventListener('load', function() { hideAddressBar();});}
	function hideAddressBar(){window.scrollTo(0, 1);}
});

