﻿//Developed by Sublime Media http://sublimemedia.com

isTouchDevice = (function() {
                try {
                    document.createEvent("TouchEvent");
                    return true;
                } catch (e) {
                    return false;
                }
            }())



if (isTouchDevice){

 $("head").append("<link>");
    css = $("head").children(":last");
    css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "v/theme/touch.css"
    });
 
 
//$('#display_homepage_title2').css('background-image','url(../images/top_nav_banner3.png)');
//alert($('#display_homepage_title2').css('background-image'))
}
	

			
//intit
$(document).ready(function () {


    $(".divDisplay1").add(".divDisplay2").hide();
    $("#keys").add("#storesWA").fadeIn(400);
    $('.mainSectionDiv').each(function(index) {
    $(this).attr('id', ($(this).attr('id')+"_Wrapper"));
  });
  
  $("a.scrollLinks").click(function () {
	scrollSectionIntoView ($(this).attr("href")+'_Wrapper');
    });
  
  
	if (document.location.hash){

		if ($(document.location.hash + '_Wrapper').length){
		scrollSectionIntoView(document.location.hash + '_Wrapper');
		}
	}


   // scrollBts();
});
/*
$(window).hashchange( function(){

// Alerts every time the hash changes!

scrollSectionIntoView(location.hash  + '_Wrapper');

})*/

//jquiry scrolling
function scrollSectionIntoView(gotoSection){
//alert(window.pageYOffset + ' ' +$(window).scrollTop());
        //var anchor = $(this).attr("href")+'_Wrapper';
        var top = $(gotoSection).position().top;
        var delta = Math.abs(top - $(window).scrollTop());
		//var delta = Math.abs($(window).get().pageYOffset - $(window).scrollTop());
		
        var t = delta * 0.8;
        $("html, body").stop().animate({ scrollTop: top }, t);
}
/*
function scrollBts() {
    $("a.scrollLinks").click(function () {
        var anchor = $(this).attr("href")+'_Wrapper';
        var top = $(anchor).position().top;
        var delta = Math.abs(top - $(window).scrollTop());
        var t = delta * 0.8;
        $("html, body").stop().animate({ scrollTop: top }, t);
        return false;
    });
}*/

//hides colloction divs on intit
function hideDivs1() {
	
    $(".divDisplay1").stop(true,true).fadeOut(300);
	
}

//hide/show colloction divs
function showCollection(id) {
    hideDivs1();
	scrollSectionIntoView ('#collections_Wrapper');
    switch (id.toLowerCase()) {

        case "linkkeys":
            $("#keys").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/35.htm");
            break

        case "linkpoker":
            $("#poker").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/110.htm");
            break

        case "linksilver":
            $("#silver").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/24.htm");
            break

        case "linkwatch":
            $("#watch").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/88.htm");
            break

        case "linkbeach":
            $("#beach").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/23.htm");
            break

        case "linkorchids":
            $("#orchids").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/60.htm");
            break

        case "linkpetals":
            $("#petals").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/96.htm");
            break

        case "linkhardware":
            $("#hardware").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/175.htm");
            break

        case "linkspectrum":
            $("#spectrum").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/176.htm");
            break

        case "linkchandelier":
            $("#chandelier").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/177.htm");
            break

        case "linkskeleton":
            $("#skeleton").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/178.htm");
            break

        case "linkfloating":
            $("#floating").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/179.htm");
            break

        case "linkroundelle":
            $("#roundelle").delay(300).fadeIn(400);
            $("#storeLink").attr("href", "http://www.teresadeleen.com/category_s/180.htm");
            break

        default:
    }

}

//hides show retail divs on intit
function hideDivs2() {
    $(".divDisplay2").fadeOut(300);
}

//hide/show retail divs
function showRetail(id) {
    hideDivs2();
    switch (id) {

        case "linkWa":
            $("#storesWA").delay(300).fadeIn(400);
            break

        case "linkOr":
            $("#storesOR").delay(300).fadeIn(400);
            break

        case "linkOl":
            $("#storesOT").delay(300).fadeIn(400);
            break

        default:
    }

}

//for images functions from Adobe
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_showHideLayers() { //v9.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3)
        with (document) if (getElementById && ((obj = getElementById(args[i])) != null)) {
            v = args[i + 2];
            if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'collapse' : v; }
            obj.visibility = v;
        }
}




//add swipe events

$(document).ready(function() {

// If the screen orientation is defined we are in a modern mobile OS
var agent = navigator.userAgent.toLowerCase();


//var mobileOS = typeof orientation != 'undefined' ? true : false;
var iOS = false

	if(navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPad") != -1 || navigator.platform.indexOf("iPod") != -1){
		iOS=true;
	}

// If the user agent string contains "android" then it's Android. If it
// doesn't but it's not another browser, not an iOS device and we're in
// a mobile and touch OS then we can be 99% certain that it's Android.
var android = false
if (agent.indexOf("android") != -1){
	android = true;
}

//hack to enable android when story body gets too big
if($("#storyBody").height()>1200){
	android=true
}
if (android){

 $("head").append("<link>");
    css = $("head").children(":last");
    css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "v/theme/android.css"

    });
}

if (iOS){
	  $('.divDisplay1').addSwipeEvents(function(evt, touch) {
	 if(window.innerWidth >= document.body.clientWidth) {
	 //works on iOS only - detects if we are zoomed out
		if (touch.eventType =='swipeleft'){
		//alert(document.body.clientWidth + " " + document.body.offsetWidth + " " + document.documentElement.offsetWidth + " " +window.innerWidth +" " +screen.width);
			if ($('.divDisplay1:visible ~.divDisplay1').length){
			showCollection("link" +$('.divDisplay1:visible ~.divDisplay1').get(0).id);
			}else{
			showCollection("link" +$('.divDisplay1:first').get(0).id);
			}
		}else if (touch.eventType =='swiperight') {

		

			if ($('.divDisplay1:visible').prev('.divDisplay1').length){
				showCollection("link" +$('.divDisplay1:visible').prev('.divDisplay1').get(0).id);
			}else{
			
				showCollection("link" +$('.divDisplay1:last').get(0).id);
			}
		
		}
		//$('#results').prepend("<li>" + touch.eventType + "</li>")
	  }})
  }
  
  
})


