$j=jQuery.noConflict();

$j(document).ready(function(){   
    alert_box(); 
});   

// Toggle footer sitemap
$j(function(){
    $j('.siteMap').click(function(){
        $j('#footerSidebar').slideToggle(750);        
    });
});

$j(function(){
    $j('#footerSidebar .close').click(function(){
        $j('#footerSidebar').fadeOut(750);        
    });
});

function alert_box() {
    // http://www.sitepoint.com/forums/javascript-15/jquery-find-replace-text-636480.html
    // This finds the first word in an element whose class is .alertbox, then wraps word in span tag to highlight word.
    $j('.alertbox').each(function() {
        var str = $j(this);
        str.html(str.html().replace(/^(\w+)\:/, '<span>$1:</span>'));
    });
}

// pop-up window
// attr = onclick="poptastic(this.href); return false;"
var newwindow; 
function poptastic(url)
{
    newwindow=window.open(url,'name');
    if (window.focus) {newwindow.focus()}
}

// email scramble
function stringReverse(textString) {
   if (!textString) return '';
   var revString='';
   for (i = textString.length-1; i>=0; i--)
       revString+=textString.charAt(i)
   return revString;
}

function email_address_text(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography. - your email client will open.">');    
    document.write(emLink); 
    document.write("</a>");  
}

function order_by_email(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a class="orderByEmail" href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography. - your email client will open.">');    
    document.write('Order by Email'); 
    document.write("</a>");  
}

function show_contact_me_text(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography. - your email client will open.">');    
    document.write('contact me'); 
    document.write("</a>");  
}

function show_email_me_text(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography. - your email client will open.">');    
    document.write('email me'); 
    document.write("</a>");  
}

function show_email_text(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography. - your email client will open.">');    
    document.write('email'); 
    document.write("</a>");  
}

function email_btn(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    document.write('<a class="emailBtn" href="mailto:' + emLink + '" title="Click to email David Gubernick and Rainbow Spirit Photography">');   
    document.write('<span class="replaceTextWithGraphic">' + emLink + '</span>'); 
    document.write("</a>");
}

function email_address(userName,emServer) {
    userName = stringReverse(userName); 
    emServer = stringReverse(emServer); 
    var emLink = userName+"@"+emServer; 
    //document.write('<a href="mailto:' + emLink + '" title="Click link to contact us via email">');    
    //document.write(emLink);
}

//<script type="text/javascript">email_address_text("ofni","moc.tiripswobniar") </script>

// Gallery image display
$j(document).ready(function(){
    $j('#gallery-slideshow').cycle({
        fx: 'fade',
        speed: 750,
        timeout: 0,
        delay: -2000,
        pager: '.pager-thumbnail',
        after: onAfter,
        pagerAnchorBuilder: function(idx, slide) {
            var img = $j(slide).children().eq(0).attr("src");
            var alt = $j(slide).children().eq(0).attr('alt');
            return '<img src="' + img + '" width="75px" height="75"  alt="Thumbnail of' + alt + '" title="Click to view a larger version of ' + alt + '" />';
        }
    }); 
});

$j(document).ready(function(){
    $j('.home-slideshow').cycle({
        fx: 'fade',
        speed: 750,
        timeout: 4000,
        delay: -2000
    }); 
});

// Sets the title for the gallery slideshow
function onAfter(curr,next,opts) {
    var title = $j(this).children().attr('alt');
    var href = $j('.orderByEmail').attr('href');
    $j('.orderByEmail').attr('href', "mailto:info@rainbowspirit.com?subject=I'm interested in: " + title);
    $j('.orderByEmail').attr('title', "Click if you would like to order " + title + " directly from David. Your email client will open.");
}



