﻿var detectMobile = {
    init: function () {

        var PhoneLink;
        var iPodAgent = navigator.userAgent.match(/iPhone/i) != null;
        var AndroidAgent = navigator.userAgent.match(/Android/i) != null;
        var AndroidLink = "https://market.android.com/details?id=com.trivera.nerolispa&hl=en";
        var iPhoneLink = "http://itunes.apple.com/us/app/neroli-spa/id442427795?mt=8";

        if (AndroidAgent) {
            PhoneLink = AndroidLink;
        } else if (iPodAgent) {
            PhoneLink = iPhoneLink;
        }
		
        if (iPodAgent || AndroidAgent) {            
            mobileModal.make(PhoneLink);
        }
    }
}

var mobileModal = {
    make: function (PhoneLink) {
		var modalHtml = '<div id="modal"><img src="http://www.nerolispa.com/wp-content/themes/neroli/images/phones.jpg" alt="iPhone and Android Phone" /> <h3>Download the Free App!</h3> <a href="' + PhoneLink + '"><img src="http://www.nerolispa.com/wp-content/themes/neroli/images/download-btn.gif" alt="Download" /></a><a href="" id="close">No thanks. Take me to the site.</a></div> <div id="mask">&nbsp;</div>'
        
		$('body').prepend(modalHtml);
		$('#mask').height(900).width(900).show();
        $('#modal').show();

        $('#mask, #close').live('click', function (e) {
            mobileModal.destroy();	
			 $.cookie('viewMobilePanel', 'closed', {path: "/"});
            e.preventDefault();
        });
    },
    destroy: function () {
        $('#mask, #modal').hide().remove();
    }
}

var detectCookie = {
	init: function () {

		// Panel State
		var viewMobilePanel = $.cookie('viewMobilePanel');
		
		// Set the user's selection for the Mobile Panel
		if (viewMobilePanel == 'closed') {
			// Do nothing...
		} else {
			detectMobile.init();
		};
	}
}

function initialize() {
	detectCookie.init();
}

$(document).ready(function () {
	initialize();
	
	//Main Navigation
	$(function () {
		$("ul.nav li").hover(function () {
			$(this).addClass("hover");
			$('ul:first', this).css('visibility', 'visible');
			$('div:first', this).css('visibility', 'visible');
		}, function () {
			$(this).removeClass("hover");
			$('ul:first', this).css('visibility', 'hidden');
			$('div:first', this).css('visibility', 'hidden');
		});
		$("ul.nav li ul li:has(ul)").find("a:first").append("");
	});							
							
    $('.screen-reader-text').hide();
	
	$('div#slider a').hide();
	$('div#slider a:first-child').show();
    $('#slider').nivoSlider({
        effect: 'sliceUpLeft',
        slices: 15,
        animSpeed: 400,
        pauseTime: 5000,
        startSlide: 0, //Set starting Slide (0 index)
        directionNav: true, //Next & Prev
        directionNavHide: false, //Only show on hover
        controlNav: false, //1,2,3...
        controlNavThumbs: false, //Use thumbnails for Control Nav
        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
        beforeChange: function () { },
        afterChange: function () { },
        slideshowEnd: function () { } //Triggers after all slides 
    });							
							
    $("#s").val("Search...");
    $("#s").focus(function () {
        if ($(this).val() == "Search...") {
            $(this).val("");
        }
    }).blur(function () {
        if ($(this).val() == "") {
            $(this).val("Search...");
        }
    });
});
