
// normal sections
$(document).ready(function () {
    $("#pics img").bind('click', function () {
        var picurl = $(this).attr("src");
        updateStats(picurl)
    })
})
// archive
$(document).ready(function () {
    $(".imagesets img").bind('click', function () {
        var picurl = $(this).attr("src");
        updateStats(picurl)
    })
})

function updateStats(filename) {
    $.ajax({
        type: 'POST',
        url: '/portfolio/logstats',
        data: {filename: filename}
//        success: success,
//        dataType: dataType
    });

    //$.get('/picopened.htm', function (data) {
        //$('.result').html(data);
      //  alert('Load was performed.');
    //});

   
}


$(document).ready(function () {
    $.get('http://www.200towns.co.uk/webforms/updateTweets.aspx', function (data) {
        data = data.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
        data = data.replace("<result>", "");
        data = data.replace("</result>", "");
        //    alert(data);
        //  var id = document.getElementById("wikitextbox");
        //  id.innerHTML = "" + data; // data;
        // alert(data);
    });

    $.get('http://www.martinruffe.co.uk/webforms/updateTweets.aspx', function (data) {
        data = data.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
        data = data.replace("<result>", "");
        data = data.replace("</result>", "");
        //    alert(data);
        //  var id = document.getElementById("wikitextbox");
        //  id.innerHTML = "" + data; // data;
        // alert(data);
    });

});

// carousel

/*

var mycarousel_itemList = [
    { url: "http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg", title: "Flower1" },
    { url: "http://static.flickr.com/75/199481072_b4a0d09597_s.jpg", title: "Flower2" },
    { url: "http://static.flickr.com/57/199481087_33ae73a8de_s.jpg", title: "Flower3" },
    { url: "http://static.flickr.com/77/199481108_4359e6b971_s.jpg", title: "Flower4" },
    { url: "http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg", title: "Flower5" },
    { url: "http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg", title: "Flower6" },
    { url: "http://static.flickr.com/58/199481218_264ce20da0_s.jpg", title: "Flower7" },
    { url: "http://static.flickr.com/69/199481255_fdfe885f87_s.jpg", title: "Flower8" },
    { url: "http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg", title: "Flower9" },
    { url: "http://static.flickr.com/70/229228324_08223b70fa_s.jpg", title: "Flower10" }
];*/


tb_pathToImage = "http://www.martinruffe.co.uk/Scripts/images/loadingAnimation.gif";

function mycarousel_itemLoadCallback(carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        // Create an object from HTML
        var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList[i - 1])).get(0);

        // Apply thickbox
        tb_init(item);

        carousel.add(i, item);
    }
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item) {
    var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
    return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="200" height="200" border="0" alt="' + item.title + '" /></a>';
};

jQuery(document).ready(function () {
    id2 = document.getElementById("carousel");
    if (id2) {
       //;
    }
});

// ****************************************

//** flash detection using iphone ipad etc method

function iphone_etc() {
    var isiphone = false;
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        
        if (document.cookie.indexOf("iphone_redirect=false") == -1)
        {
         isiphone=true;
         }
         return isiphone;
       
    }
}



// ** flash detection end


// JavaScript Document

function init() {
    id1 = document.getElementById("flashwrapper");

    try {
       id1.style.display = "block";
    }
    catch (err)  { ; }

    $(document).ready(function () {
        
        $("a[rel^='prettyPhoto']").prettyPhoto();


        // ** code to display flash or jquery

        // try {
        
        id2 = document.getElementById("carousel");
        if (id1) {
            if (iphone_etc() == true) {
                id1.style.display = "none";
                id2.style.display = "block";
                jQuery('#mycarousel').jcarousel({
                    size: mycarousel_itemList.length,
                    itemLoadCallback: { onBeforeAnimation: mycarousel_itemLoadCallback }
                });

            }
            else {
                id2.style.display = "none";
                id1.style.display = "block";
            }
        }
        // }
        //catch { ; }

        // ** end
    });
		//alert('hi');
}


function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

//================================
// bookmarks

function buildhtml(sn, i, url) {
    root = 'http://www.martinruffe.co.uk/nav_images/socialnetwork/'; // for site

    add = 'Add to: ' + sn;
    i = '<img alt="' + add + '" title="' + add +
    '" src="' + root + i + '" />';
    imageandurl = '<a target="_blank" href="' + url + '">' + i + '</a>';
    return imageandurl;
}



function get_del(url, title, text) {
    sn = 'Delicious';
    i = 'delicious_16.png';
    url = 'http://delicious.com/post?url=' + url + '&title=' + title + '&notes=' + text
;
    return buildhtml(sn, i, url);
}

function get_digg(url, title, text) {
    sn = 'Digg';
    i = 'digg_alt_16.png';
    url = 'http://digg.com/submit?phase=2&url=' + url + '&title=' + title + '&bodytext=' + text;
    return buildhtml(sn, i, url);
}

function get_dzone(url, title, text) {
    sn = 'Dzone';
    i = ''; //no image
    url = 'http://www.dzone.com/links/add.html?url=' + url + '&title=' + title;
    return buildhtml(sn, i, url);
}

function get_face(url, title, text) {
    sn = 'Facebook';
    i = 'facebook_16.png';
    url = 'http://www.facebook.com/share.php?u=' + url + '&t=' + title;
    return buildhtml(sn, i, url);
}

function get_my(url, title, text) {
    sn = 'MySpace';
    i = 'myspace_16.png';
    url = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + url + '&t=' + title;
    return buildhtml(sn, i, url);
}

function get_stumble(url, title, text) {
    sn = 'StumbleUpon';
    i = 'stumbleupon_16.png';
    url = 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title;
    return buildhtml(sn, i, url);
}

function get_tech(url, title, text) {
    sn = 'Technorati';
    i = 'technorati_16.png';
    url = 'http://technorati.com/faves?add=' + url;
    return buildhtml(sn, i, url);
}

function get_twit(url, title, text) {
    sn = 'Twitter';
    i = 'twitter_16.png';
    url = 'http://twitter.com/home?status=' + title + ' - ' + url;
    return buildhtml(sn, i, url);
}

function buildstrip(locationid) {
    // naughty use of innerHTML 
   

    url = '' + document.URL;
    if (url == '') {
        url = 'http://www.martinruffe.co.uk';
    }
    hashpos = url.indexOf("#");
    if (hashpos > 0) {
        url = url.substring(0, hashpos);
    }

    ptitle = '' + document.title;
    if (ptitle.indexOf('Martin Ruffe') > 0) {
        ptitle = ptitle.replace('Martin Ruffe', '');
        ptitle = ptitle.replace('|', '-');
        ptitle = ptitle.replace('|', '-');
        ptitle = ptitle.replace('|', '-');
        ptitle = ptitle.replace('|', '-');
        ptitle = ptitle.replace('|', '-');
        ptitle = ptitle.replace('- -', '-');
        ptitle = ptitle.replace('- -', '-');
        ptitle = ptitle.replace('- -', '-');
        ptitle = ptitle.replace('- -', '-');
        ptitle = ptitle.replace('-  -', '-');
        ptitle = ptitle.replace('-  -', '-');
        ptitle = ptitle.replace('-  -', '-');
        ptitle = ptitle.replace('-  -', '-');
        ptitle = ptitle.replace('  ', ' ');
        ptitle = ptitle.replace('  ', ' ');
        ptitle = ptitle.replace('  ', ' ');
    }

    if (ptitle == '') {
        ptitle = 'Martin Ruffe. Developer, Photographer';
    }
    ptext = '';
    s = '';
    s = s + get_twit(url, ptitle, ptext);
    s = s + get_face(url, ptitle, ptext);
    s = s + get_del(url, ptitle, ptext);
    s = s + get_digg(url, ptitle, ptext);
    s = s + get_stumble(url, ptitle, ptext);
    s = s + get_my(url, ptitle, ptext);
    s = s + get_tech(url, ptitle, ptext);

 //   locationid = 'social';
    var idx = document.getElementById("socialm");
  //  alert(locationid);
    idx.innerHTML = s;
    alert('social');

}

// ===========================



//addLoadEvent(buildstrip('social'));

window.onload = init; 
