/***********************
*  Site Specific JS   *
************************/

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1367/the-upholstery-centre_9e3296469a.ico','http://cdn.myld.com.au/2/1367/the-upholstery-centre_65c6c3cc27.png');
  
  menu.contactDetails({
		phone: '0243882203',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		email: 'upholsterycentre@hotmail.com',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		address: '2/5 Tumbi Creek Rd Berkeley Vale, NSW 2261',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Mon-Fri', '8:00am - 4:30pm']
			] 
			//optional 
	});
	
	//home services
	$('.htText').hide();
	$(".ht:eq(0) a").hover(
			 function () {
				 $('.htText').hide();
				 $('#htText1').show();
			 }
	 );
	$(".ht:eq(1) a").hover(
			 function () {
				 $('.htText').hide();
				 $('#htText2').show();
			 }
	 );
	$(".ht:eq(2) a").hover(
			 function () {
				 $('.htText').hide();
				 $('#htText3').show();
			 }
	 );
	$(".ht:eq(3) a").hover(
			 function () {
				 $('.htText').hide();
				 $('#htText4').show();
			 }
	 );
	 
	$('.ctText').hide();
	$("#ctRow1 .ct:eq(0) .contentThumb").hover(
			 function () {
				 $('.ctText').hide();
				 $('#ctText1').show();
			 }
	 );
	$("#ctRow1 .ct:eq(1) .contentThumb").hover(
			 function () {
				 $('.ctText').hide();
				 $('#ctText2').show();
			 }
	 );
	$("#ctRow2 .ct:eq(0) .contentThumb").hover(
			 function () {
				 $('.ctText').hide();
				 $('#ctText3').show();
			 }
	 );
	$("#ctRow2 .ct:eq(1) .contentThumb").hover(
			 function () {
				 $('.ctText').hide();
				 $('#ctText4').show();
			 }
	 );
	
	//slider
	jQuery('.camera_wrap').camera({
		random: true,
		autoAdvance: true,
		fx: 'scrollLeft',
		height: '695px',
		minHeight: '695px',
		hover: false,
		loader: 'bar',
		navigation: true,
		navigationHover: false,
		mobileNavHover: false,
		pagination: false,
		playPause: false,
		pauseOnClick: false,
		time: 4000,
		transPeriod: 1500
	});
     
});

$(window).load(function(){
	mapcanvas();
});

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	redirectLink: "http://api.jquery.com/jquery.fn.extend/",
	validateStyle: "default"
});

//map-canvas
function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-33.36005, 151.44424);
  var image = 'http://cdn.myld.com.au/2/1367/the-upholstery-centre_67d2620df7.png';
  var mapOptions = {
    zoom: 18,
		scrollwheel: false,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  
  if ($('#map-canvas').length > 0) {
      var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    
      var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          icon: image
      });
      
      google.maps.event.addDomListener(window, 'resize', function() {
			map.setCenter(myLatlng);
	  });         
      google.maps.event.addDomListener(window, 'orientationchange', function() {
			map.setCenter(myLatlng);
	  });   
	}
}

//view section 1
$('#view_section_1').insertAfter('#slider');

//error div
$('#error').insertAfter('#slider');

//nav span
//$('.navbar-nav > li > a').wrapInner('<span>');

//nav id
$('.navbar-nav').attr('id', 'topNav');

//gallery
if(Modernizr.touch && $(".fancybox").length > 0 )
{ 
   var myPhotoSwipe = $(".fancybox").photoSwipe({ enableMouseWheel: false , enableKeyboard: false });
}
else
{
/* Apply to single image */
    $("a.fancybox").fancybox();

/* Apply fancybox to multiple items */
    $("a.fancybox[rel='gallery_group']").fancybox({
        'transitionIn'    :    'elastic',
        'transitionOut'    :    'elastic',
        'speedIn'        :    600, 
        'speedOut'        :    200 
    });

/* Apply with thumbnails visible */
    $("a.fancybox").fancybox({
		helpers : {
			thumbs : {
				width: 200,
				height: 200
			}
		}
    });
}

$(window).bind("load resize scroll",function(){
	//isotope
	var $container = $('.isotope').isotope({
		"itemSelector": ".item",
		masonry: {
			columnWidth: ".item"
		}
	});
});

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}

$(function() {

	var $el, leftPos, newWidth,
			$mainNav = $("#topNav");
	
	$mainNav.append("<li id='magic-line'></li>");
	var $magicLine = $("#magic-line");
	
	$magicLine
			.width($(".active").width())
			.css("left", $(".active a").position().left)
			.data("origLeft", $magicLine.position().left)
			.data("origWidth", $magicLine.width());
			
	$("#topNav li a").hover(function() {
			$el = $(this);
			leftPos = $el.position().left;
			newWidth = $el.parent().width();
			$magicLine.stop().animate({
					left: leftPos,
					width: newWidth
			});
	}, function() {
			$magicLine.stop().animate({
					left: $magicLine.data("origLeft"),
					width: $magicLine.data("origWidth")
			});    
	});
});