var quotes = {
'a' : '<blockquote><p>"The book is encouraging, positive, uplifting and practical. It should be read by all. The book has so much common sense which is very rare these days and everyone who reads it will be better off by the experience." <cite>Kell Ryan<br> Retired Executive – Ryanair<br> <a href="http://www.speakers.co.uk">www.speakers.co.uk</a></cite></p> </blockquote><blockquote><p>"I received your book last night and read it in one sitting. It should be required reading for anyone who has ever felt that they are not able to change – and you can quote me on that!" <cite>Ursula James<br> This Morning’s resident Clinical Hypnotherapist and star of her own TV show,Sex, Lies and Hypnotherapy<br> <a href="http://www.ursulajames.com">www.ursulajames.com</a></cite></p></blockquote>',
'b' : '<blockquote><p>"I can’t wait to read the book. Love, light and happiness to you. xxx"<cite>Darius Campbell<br />Actor, Singer and Pop Star<br> <a href="http://www.dariusmusic.com">http://www.dariusmusic.com</a></cite></p></blockquote>',
'c' : '<blockquote><p>“How does one become a Butterfly? You must want to fly so much that you are willing to give up being a caterpillar.”<cite>E. Deborah Chaskin</cite></p></blockquote>',
'd' : '<blockquote><p>“I was very nervous and anxious as my Driving Test grew closer. After a few sessions with Karen, she very quickly turned me around to a very relaxed and focussed driver. I am delighted to say PASSED FIRST TIME“<cite>Jennifer (age 17 years)</cite><p></blockquote><blockquote><p>“I met Karen at a time in my life when i wasn’t feeling great about myself. I was stuck in a bit of a rut. Karen showed me a different way to look at my life and told me the things I needed to hear at the time.</p><p>She helped me to help myself move on. I still find myself going back to the things Karen advised me to do and her methods continue to help me out.</p><p>Karen gave me the push I needed to start a new chapter of my life, for which I am very grateful!”</p><cite>Jenna Clyne</cite></blockquote>',
'e' : '<blockquote><p>“Most moving, wonderful weekend of learning”<br> “Karen is a figure of inspiration” <cite>Bernadette Doyle<br> Fitness Trainer</cite></p></blockquote>',
'f' : '<blockquote><p>“You gave me more than Reiki”<cite>Cheryl McDowell</cite></p></blockquote>',
'g' : '<blockquote><p>“A positive and inspirational weekend” <cite>Paula Clarkston</cite></p></blockquote>',
'h' : '<blockquote><p>“The start of the rest of my life” <cite>Maggie Crow</cite></p></blockquote>',
'i' : '<blockquote><p>“A wonderful journey into the light, guided by a true Master”<cite>David Waddell<br> Herbalist/Hypnotherapist</cite></p></blockquote>',
'j' : '<blockquote><p>“Yesterday is gone.<br> Tomorrow has not yet come.<br> We have only today. Let us begin” <cite>Mother Teresa</cite></p></blockquote>',
'k' : '<blockquote><p>“With Karen’s invaluable insights and teaching, I was able to transform my life from feeling totally helpless, unhappy and stagnant to being vibrant, positive, happy and complete. She helped me make the right decisions and together we achieved amazing changes from both a personal and business level. Every aspect of my life has turned around and all for the better. With Karen’s guidance, techniques and tools (which I use daily) we achieved amazing results. <cite>Aileen Campbell</cite> </p></blockquote>',
'l' : '<blockquote><p>"Karen is my angel on earth! She taught me how to turn my dreams into reality. Effortlessly! Within eight weeks of seeing Karen, my life had changed immeasurably! Thank you". <cite>Louise Arrol<br>Advocate</cite></p><blockquote>'
};




//----------------------------------------------------------------------------
//FUNCTIONS/EMBEDS

//for debugging, call on obj before alert
function co(obj) { 
    str='';
    for (prop in obj) {
        str += prop + " value :" + obj[prop] + "\n";
    }
    return(str);
}

function cv_sidebar() {
    var ii, jj, kk;
    var sidebar = '';
    var id = Math.floor(Math.random()*13) + 1; // buddha (14) etc only on certain pages
    
    if ($('body.home').length) {  
        return false;
    } else if ($('body#workshops:not(body.pageid-37)').length || $('body.pageid-57').length) { // reiki, hypno
        sidebar += '<img src="/media/images/polaroid.php?id=13" id="pol1" class="polaroid">';
    } else if ($('body.pageid-12').length) {
        id = 15; // Karen
        sidebar += '<img src="/media/images/polaroid.php?id='+id+'" id="pol1" class="polaroid">';
    } else if ($('body.pageid-35').length) {
        id = 7; // Guy on rock
        sidebar += '<img src="/media/images/polaroid.php?id='+id+'" id="pol1" class="polaroid">';
    } else if ($('body.pageid-37').length) {
        sidebar += '<img src="/media/images/polaroid.php?id='+id+'" id="pol1" class="polaroid">';
    } else {
        id = Math.floor(Math.random()*13) + 1; // buddha only on certain pages
        sidebar += '<img src="/media/images/polaroid.php?id=' + id + '" class="polaroid">\n';
    }
    
    sidebar += '<div id="quote_box">';
    if ($('body.pageid-18').length) sidebar += quotes['a']; // book
    if ($('body.pageid-57').length) sidebar += quotes['l']; // hypno
    if ($('body.pageid-37').length) sidebar += quotes['c']; // workshops
    //if ($('body.pageid-35').length) sidebar += quotes['b']; // coaching
    if ($('body.pageid-52').length) sidebar += quotes['k']; // 1to1
    if ($('body.pageid-55').length) sidebar += quotes['d']; // teenage
    if ($('body.pageid-70').length) sidebar += quotes['e']; // reiki i
    if ($('body.pageid-72').length) sidebar += quotes['f']; // reiki ii
    if ($('body.pageid-72').length) sidebar += quotes['g']; // reiki ii
    if ($('body.pageid-74').length) sidebar += quotes['h']; // reiki iii
    if ($('body.pageid-74').length) sidebar += quotes['i']; // reiki iii
    if ($('body.pageid-61').length) sidebar += quotes['j']; // reiki iii
    sidebar += '</div>';
    
    $('#sidebar').html(sidebar);
}

// embedded http://blog.james-carr.org/2009/04/12/jquery-text-tools-link-urls-with-jquery/
(function(){if(jQuery){jQuery.extend({link:function(a){if(a){return a.replace(/(href="|<a.*?>)?[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g,function(a,b){return b?a:a.link(a)})}}});jQuery.fn.extend({link:function(){this.html($.link(this.html()))}})}})()


// embedded URLencode plugin - http://0061276.netsolhost.com/tony/testurl.html
$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});


// Preload -------------------------------------------------------------------

// Flash for HP --------------------------------------------------------------
swfobject.registerObject("photostack", "9.0.115", "/media/flash/expressInstall.swf");


// JQuery DOM LOADS ----------------------------------------------------------
$(function() {
    // IE6
    $('#root').supersleight({shim: '/media/images/x.gif'});
    
    var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase());
    
    cv_sidebar();
    
    // safe default in CSS and override here. JS keeps breaking (CC?) and site needs to at least look OK
    // $('#root').css('padding-top', '0');
    // $('h1').css('margin-top', '-77px');
    // $('h1').css('height', '75px');
    // $('h1').css('padding-bottom', '13px');
    // $('#nav').css('margin-top', '-33px');
    
    // GA - right a/c number? Who has access? Karen?
    if (location.hostname == 'www.thebutterflyexperience.com') {
        $.geekGaTrackPage('UA-2280676-1"');
    }
        
    // Search prompt
    $('input#s, input#s-no-results, input#s-404').val('Search').css('color', '#ccc');
    $('input#s, input#s-no-results').click(function() {
        $(this).css('color', '#696969').val('');
    });
    
    // Contact form - allows CC to sender
    $('.cc-email input').val($('.your-email input').val()); 
    // not just .click() append so box left unticked but synced from start
    $('#cc-optin').click(function() {
        if ($('#cc-optin:checked').length) {
            $('.cc-email input').val($('.your-email input').val());
        } else {
            $('.cc-email input').val('');
        }
    });
    
    // Feature tabs
    var tab_duration = 150; //time in miliseconds
    var tab_move = "5px";
    $('.tab').hover(function() {
        $(this).find('img').animate({top: tab_move}, tab_duration);            
    }, function() {
        $(this).find('img').animate({top: 0}, tab_duration);
    });
    
    // News ticker
    $("#newsflash_content").liScroll({travelocity: 0.03});
    
    // Now just misc fixes all over ------------------------------------------
        
    // IE 7/8 (6 OK?!) was mishandling background-image position in top right, this luckily fixes in circs
    // $('#cctr:first div').css('background-image','');
    // $('#cctl:first div').css('background-image','');
    
    //$('#cctl:first div').css('background-image','');
    
    // IE6 - curve aligns with bottom of vewport, cannot fix, shelving
        
    $('#content .section:last').css('margin-bottom', '0');
    if ($.browser.webkit) $('#newsflash h4').css('margin-top', '4px');
    
    if ($('#newsletter_form').length) {
        var tt = $('#newsletter_form table tr:first td');
        var title = tt.html();
        $(tt).html('<h3>'+title+'</h3>');
            $('#newsletter_form table tr:last').hide();
            $('#newsletter_form table tr:first').css('height', '50px');
            //$('#newsletter_form').corner(settings_section);
            
    }
    
    // fix annoying photo gallery issue
    $('h2.album_title').hide();
    // for the usual non :first-child suspects
    $('#nav li:first').css('background', 'none');
    
    $('.pageid-212 .imagedesc').link();

    if ($('#home.home h2').length) {
        //big_cap();
         var t = $('#home h2:first').html();
         var f = t.substring(0,1);
         var rest = t.substring(1);
         t = "<span class='bigcap'>" + f + "</span>" + rest;
         $('#home h2').html(t);
    }
        
    if ($('body.pageid-212').length) {
        var motto = $('#gallery-motto').html();
        $('h2:first').after('<h3 id="new-gallery-motto">'+motto+'</h3>');
        $('gallery-motto').show();
    }

    var iii = 0;
    $('#products div.product_grid_item').each(function(){
        iii++;
        if (iii%3 == 0) $(this).css('margin-right', '0');
    });
    
    $('#products div.product_grid_item').equalHeights(100, 350);
    
    if ($('body.pageid-201').length) {
        $('#sidebar').hide();
    }

    $('#news_signup').val('Free Newsletter');
    $('#tele_signup').val('Free Monthly Tele-Training');
    $('.signup').css('color', '#352594');
    
    // quick fix for a misunderstanding/mis-spec
    $('#news_signup').click(function() {
        location.href = "/latest/newsletter/";
    });
    
    $('#tele_signup').click(function() {
        location.href = "/contact/tele-training/";
    });
    
    $('#soc_nets img:first').css('margin-right', '10px');
    
    $('.product_grid_display:last-child').css('margin-right', '0');
    
    if (location.href.indexOf('/products/') > -1) $('#contact_box').hide();
    
    if (!$('#quote_box').text().length) $('#quote_box').hide();
    if (location.href.indexOf('/latest/gallery/') > -1) $('#contact_box').hide();

    $('.pageid-434 h2').html('<strong>The Butterfly Experience</strong> — Tele-Training');

    if ($.browser.webkit) {
        $('#content').css('margin-bottom', '-54px'); // odd, but big margin otherwise
        $('#sig').css('margin-bottom', '64px'); // odd, but big margin otherwise        
    }
    
    //if ($.browser.mozilla) $('#nav li:first').css('padding-right', '10px');
    


    // Shop
    
    // #products div.product_grid_display {
    //     padding-bottom: -40px;
    // }

    $('#products div#products_page_container').css('padding', '0');
    
    // set bot margin of last line to zero
    var item_total = $('#products div.product_grid_item').length;
    $('#products div.product_grid_item').each(function(i) {
        if (item_total - i <= 3) {
            $(this).css('margin-bottom', '0');
        }
    });
    
    //$('#shoppingcartcontents').corner(settings_section);
    $('#products #shoppingcart h3').prepend('<img src="/media/images/cart-icon.png">'); //here to avoid core hacking
    
    $('#products #shoppingcart table tr').each(function(i) {
        if (i % 2) $(this).find('td').css('background-color', '#F6F6F6');
        else $(this).find('td').css('background-color', '#E9E9E9');
    })
    
    
    /* the shopping cart widget would overflow short pages otherwise */
    if ($('body.wpsc-single-product').length) {
        var browser_offset = 0;
        var single_page_offset = 0;
        
        if ($.browser.webkit) browser_offset = 70;
        if ($.browser.webkit && is_chrome) browser_offset = 100;
        if ($.browser.mozilla) browser_offset = 50;
        if ($.browser.msie) browser_offset = 100;
        
        single_page_offset = $('#shoppingcart').height() - $('.wpsc-single-product #content').height() + browser_offset;
        $('.wpsc-single-product #content').css('padding-bottom', single_page_offset+'px');
        
        $('.wpsc_buy_button').click(function(){
            window.location.href = window.location.href; // ajax add button on single page needs this for redraw
        });        
    }
    
    if (is_chrome &&  $('body.wpsc-shopping-cart')) {
        $('#content').css('padding-bottom', '50px');
    }
    
    if ($.browser.mozilla &&  $('body.wpsc-shopping-cart')) {
        $('#content').css('padding-bottom', '0');
    }
    
});

