;(function($) {
$(document).ready(function() {
	//$('#body').MScroll();
	//$.mscroll();

	if($('#bd-contact').length) {
		$('#qvb div.map').gMap({
			latitude: -33.870990,
			longitude: 151.206583,
			maptype: 'ROADMAP',
			zoom: 17,
			controls: {
				panControl: false,
				zoomControl: true,
				mapTypeControl: false,
				scaleControl: false,
				streetViewControl: false,
				overviewMapControl: false
			},
			markers:[{
				latitude: -33.870990,
				longitude: 151.206583,
				html: "QVB"
			}]
		});
		$('#chase div.map').gMap({
			address: "345 Victoria Avenue, Chatswood, NSW, 2067, Australia",
			maptype: 'ROADMAP',
			zoom: 17,
			controls: {
				panControl: false,
				zoomControl: true,
				mapTypeControl: false,
				scaleControl: false,
				streetViewControl: false,
				overviewMapControl: false
			},
			markers:[{
				address: "345 Victoria Avenue, Chatswood, NSW, 2067, Australia",
				html: "Chatswood Chase Sydney"
			}]
		});
		/*
		$('#contact-form').dialog({
			title: 'Contact Us',
			autoOpen: false,
			show: 'slide',
			minWidth: 428,
			buttons: [{
				text: 'Submit',
				click: function() {
					$('#contact-form input.cat_button').trigger('click');
				}
			}, {
				text: 'Cancel',
				click: function() {
					$(this).dialog('close');
				}
			}]
		});
		$('a.email-contact').click(function(e) {
			e.preventDefault();
			$('#contact-form').dialog('open'); 
		});
		*/
		$('#qvb a.centre-map').click(function(e) {
			e.preventDefault();
			$('#map-qvb').show(); 
		});
		$('#chase a.centre-map').click(function(e) {
			e.preventDefault();
			$('#map-chase').show(); 
		});
		$('a.email-contact').click(function(e) {
			e.preventDefault();
			$('#contact-form').show(); 
		});
		$('a.newsletter').click(function(e) {
			e.preventDefault();
			$('#newsletter-form').show();
		});
		$('a.hiring').click(function(e) {
			e.preventDefault();
			$('#careers-form').show(); 
		});
		
	}
	$('#products-list a').click(function(e) {
		//e.preventDefault();
	});
	/*
	$('#collections').click(function(e) {
		e.preventDefault();
		$.mscroll._moveTo(-1890);
		console.log($.mscroll); 
	});
	*/
	if($('div.popup').length) {
		$('.popup-close, div.ui-widget-overlay').click(function(e) {
			e.preventDefault();
			$(this).parents('div.popup').hide();
		});
		$('div.popup label:not(.cv):not(.captcha)').labelsFX({
			fx: 'slide' 
		});
	}
	

	// Product detail page
	if($('#item').length) {
		$('ul#extra-images li').each(function(index) {
			if($(this).children('a').attr('href')=='') {
				$('#view li.' + $(this).attr('class')).remove();
				$(this).remove();
			} else {
				$(this).show();
			}
			$(this).children('a').click(function(e) {
				e.preventDefault();
			})
		});
		$('ul#extra-images li a').hoverIntent({
			over: function() {
				$(this).addClass('hover');
				var image = $(this).parent().attr('class');
				if(!$('#view li.' + image).is(':visible')) {
					$('#view li:visible').fadeOut();
					$('#view li.' + image).fadeIn();
					$('ul#extra-images li a').removeClass('selected');
					$(this).addClass('selected');
				}
			},
			out: function() {
				$(this).removeClass('hover');
			},
			timeout: 200
		});
		$('#media-thumbs li').each(function(index) {
			var medialink = $(this).children('span').children('a').attr('href');
			if(medialink.split('/')[2] != '00-no-media') $(this).children('a').attr('href',medialink);
			else $(this).remove();
		});
	}
	if($('#media').length) {
		//$('#media div.right #actionbar').height($('#media div.right').height());
		var slideshow=true;
		$('#embed').children().each(function(index) { if(!($(this).is('img') || $(this).is('br'))) slideshow=false; });
		if($('#embed img').length==1) slideshow=false;
		
		if($('a.audio').length) {
			//$('#embed').append('<div id="apple-controls" class="controls"></div>');
			var cover = $($('a.audio').attr('id','player').html()).attr('src');
			$('#player').html('');
			/*
			$.getScripts([
				'/js/flowplayer-3.2.6.min.js',
				'/js/flowplayer.ipad.js',
				'/js/flowplayer.controls-3.0.2.min.js'
			], function() {
			*/
			$.getScript('/js/flowplayer-3.2.6.min.js', function(data, textStatus){
			$.getScript('/js/flowplayer.ipad.js', function(data, textStatus){
				flowplayer("player",
				{
					src: "/js/flowplayer-3.2.7.swf",
					wmode: 'transparent'
					
				}, {
					clip: {
						autoPlay: false,
						autoBuffering: true, 
						coverImage: { url: cover, scaling: 'scale' }
					},
					plugins: {
						controls: {
							autoHide: false
						}
					}
				}).ipad({ simulateiDevice: false, controls: true});
			});
			});
		}
		
		if(slideshow) {
			$('#embed br').remove();
			$.getScript('/js/jquery.nivo.slider.pack.js', function(data, textStatus){
				$('#embed')
				.height($('#embed img:eq(0)').height())
				.width($('#embed img:eq(0)').width())
				.addClass('slideshow')
				.nivoSlider({
					// sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade,
					// random, slideInRight, slideInLeft, boxRandom, boxRain, boxRainReverse, boxRainGrow, boxRainGrowReverse
					effect: 'sliceDownRight', 
					slices: 10, // For slice animations
					boxCols: 4, // For box animations
					boxRows: 8, // For box animations
					animSpeed: 800, // Slide transition speed 
					pauseTime: 6000, // How long each slide will show
					startSlide: 0, // Set starting Slide (0 index)
					directionNav: true, // Next & Prev navigation
					directionNavHide: false, // Only show on hover
					controlNav: true, // 1,2,3... navigation
					controlNavThumbs: false, // Use thumbnails for Control Nav
					controlNavThumbsFromRel: false, // Use image rel for thumbs
					controlNavThumbsSearch: '.jpg', // Replace this with...
					controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
					keyboardNav: true, // Use left & right arrows
					pauseOnHover: true, // Stop animation while hovering
					manualAdvance: false, // Force manual transitions
					captionOpacity: 0.8, // Universal caption opacity
					prevText: 'Prev', // Prev directionNav text
					nextText: 'Next', // Next directionNav text
					beforeChange: function(){}, // Triggers before a slide transition
					afterChange: function(){}, // Triggers after a slide transition
					slideshowEnd: function(){}, // Triggers after all slides have been shown
					lastSlide: function(){}, // Triggers when last slide is shown
					afterLoad: function(){} // Triggers when slider has loaded
				});
			});
		}
	}
	if($('#action-bottom').length) {
		$('#action-bottom li.share a').click(function(e) {
			e.preventDefault();
			$('#share').show();
			//$('#RFMessage').val($('h1.title').text() + '\n' + $('#description').text());
		});
		$('#action-bottom li.enquire a').click(function(e) {
			e.preventDefault();
			$('#contact-form textarea').val('I\'m enquiring about ' + $('h1.title').text() + ':\n');
			$('#contact-form textarea').prev().children('label').css('left','-9000px');
			$('#contact-form').show();
		});
	}
})
})(jQuery);
jQuery.getScripts = function(scripts, onComplete) {
	var i = 1;
	var ii = scripts.length; 
	var onScriptLoaded = function(data, response) { if (i++ == ii) onComplete(); } ; 
	for(var s in scripts) { $.getScript(scripts[s], onScriptLoaded); } ;
};
