// JavaScript Document

function bindPageFlip() {
	$("#pageflip").hover( function() {
		$("#pageflip span, #pageflip img, .msg_block").stop().animate({
			width : '275px',
			height : '275px'
		}, 500);
    }, function() {
		$("#pageflip span,#pageflip img").stop().animate( {
			width : '100px',
			height : '100px'
		}, 500);
		$(".msg_block").stop().animate( {
			width : '100px',
			height : '100px'
		}, 480); // Note this one retracts a bit faster (to prevent glitching in IE)
  });
}

function subscribe() {
	$("#ssubmit").click( function() {
		var error = 0;
		
		// check for errors
		if( $("#sname").val().length<3 ) {
			error++;
		}
		if( $("#scompany").val().length<3 ) {
			error++;
		}
		if( $("#saddress").val().length<3 ) {
			error++;
		}
		if( $("#semail").val().length<3 ) {
			error++;
		}
		if( $("#stelephone").val().length<3 ) {
			error++;
		}
		
		if( error===0 ) { // email it
			$("#subscribeForm").submit();
		} else { // error found
			alert('error found');
		}
	});
}

function navieEffect() {
	$("#navie-animate li").attr('style','padding:77px 0px 0px;');
	$("#navie li").hover( function() { //On hover...
		var theClass = $(this).children('a').html();
		$('#navie-animate li.'+theClass)
		.stop()
		.animate({padding: '0px 0px'},100);
	}, function() {
		var theClass = $(this).children('a').html();
		$('#navie-animate li.'+theClass)
		.stop()
		.animate({padding: '77px 0px 0px'},100);
	});
}

function jackBlocks() {
	$('#blocks .item').hover(
        function() { 
			$('ul', this).css('display', 'block'); 
			var self=this;
			if($.browser.msie && parseInt($.browser.version) <= 6) {
				// do nothing on ie6
			} else {
				$(this).parent('ul').children('li img').filter(function() {return self!=this;}).stop()
				.fadeTo(500,0.3);
			}
		},
        function() { 
			$('ul', this).css('display', 'none'); 
			if($.browser.msie && parseInt($.browser.version) <= 6) {
				// do nothing on ie6
			} else {
				$(this).parent('ul').children('li img').stop()
				.fadeTo(500,0.3);
			}
		}
	);
}

function videoSelect() {
	$('.videoSelector').click( function() { 
		var so = new SWFObject("../videos/mpw_player.swf", "swfplayer", "620", "270", "9", "#000000");
		so.addVariable("jpg","videopreview.jpg");
		so.addVariable("autoplay","false");
		so.addParam("allowFullScreen","true");
		so.addParam("wmode", "transparent");
		so.addVariable("backcolor","F78913");
		so.addVariable("frontcolor","FFF9CD");
		so.addVariable("flv", $(this).attr('rel')+".flv");
		so.write("videoBox");
	});
}

function handpicked(){
	$('#handpicked').cycle({ 
		fx:      'scrollDown', 
		speedIn:  2000, 
		speedOut: 500, 
		easeIn:  'bounceout', 
		easeOut: 'backin', 
		delay:   -2000 
	});
}

function galleryAutoplay(){
	setInterval((function() {
		$.galleria.next();
	}), 5000);
}

function galleryClearTime(obj) {
	$("#galleria .thumb").click( function() {
		clearInterval(obj);							  
	});
}

$(document).ready(function(){
						   
	bindPageFlip();   
	navieEffect();
	jackBlocks();

	if( $('#videoBox').length > 0 ) {
		videoSelect();
	}
	
	if( $('#ssubmit').length > 0 ) {
		subscribe();
	}
	
	if( $('#handpicked').length > 0 ) {
		handpicked();
	}
	
	// GALLERIA STARTS HERE
	/*$('#galleria').addClass('gallery');
	$('ul.gallery').galleria({
		history   : true,
		clickNext : true,
		insert    : '#main_image',
		onImage   : function(image,caption,thumb) {
			image.css('display','none').stop().fadeIn(1000);
			caption.css('display','none').stop().fadeIn(1000);
			var _li = thumb.parents('li');
			_li.siblings().children('img.selected').stop().fadeTo(500,0.3);
			thumb.fadeTo('fast',1).addClass('selected');
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) {
			var _li = thumb.parents('li');
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			thumb.css({display:'none',opacity:_fadeTo}).stop().fadeIn(1500);
			thumb.hover(
				function() { thumb.stop().fadeTo('fast',1); },
				function() { _li.not('.active').children('img').stop().fadeTo('fast',0.3); }
			);
		}
	});

	var galleriaAmf = galleryAutoplay();
	galleryClearTime(galleriaAmf);*/
	
	// GALLERIA ENDS HERE
	
});