var $j = jQuery.noConflict();
$j(document).ready(function() {
    

//$j("#toptentitle[title]").tooltip({tip: '#tooltip', effect: 'bouncy'});
//$j("#offersnotice[title]").tooltip({tip: '#tooltip', effect: 'bouncy'});

// change tab by hash in URL 27-11-2010
selectNow = 0;
var sectionFromLink = $j("#sectionfromlink").html();
if(sectionFromLink!="") {
    //alert(sectionFromLink);
$j("ul#tabstrip li").removeClass("active");
switch(sectionFromLink)
{
case "toddlertastic":
  selectNow = 1;
  $j("#tabstrip li:nth-child(2)").addClass("active");
  //$j("h2#tenbesttitle").html("Toddler-Tastic Properties");
  $j("#tenbestcaption").html("<p>10 bolt-holes that are terrific with toddlers...</p>");
  break;
case "boutique":
  selectNow = 2;
  $j("#tabstrip li:nth-child(3)").addClass("active");
  //$j("h2#tenbesttitle").html("Boutique but Baby-Friendly Properties");
  $j("#tenbestcaption").html("<p>10 bolt-holes we consider the most stylish in our collection...</p>");
  break;
case "chiconomic":
  selectNow = 3;
  $j("#tabstrip li:nth-child(4)").addClass("active");
  //$j("h2#tenbesttitle").html("Chiconomic Properties");
  $j("#tenbestcaption").html("<p>10 bolt-holes that are chic and economical...</p>");
  break;
case "romantic":
  selectNow = 4;
  $j("#tabstrip li:nth-child(5)").addClass("active");
  //$j("h2#tenbesttitle").html("Romantic yet Baby-Friendly Properties");
  $j("#tenbestcaption").html("<p>10 fabulously bolt-holes that provide parent-friendly romance..</p>");
  break;
  // second 'page' sections - these need to change the tabstrip as well
case "singleparents":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 5;
  $j("#tabstrip li:first").addClass("active");
  //$j("h2#tenbesttitle").html("Baby-Friendly Properties for Single Parents");
  $j("#tenbestcaption").html("<p>10 bolt-holes that are ideal for sociable singles with little ones..</p>");
  break;
// 19th December 2010 - swapped single parents for beachside at Sian's request
case "beachside":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 5;
  $j("#tabstrip li:first").addClass("active");
  //$j("h2#tenbesttitle").html("Beachside Baby-Friendly Properties");
  $j("#tenbestcaption").html("<p>10 bolt-holes within a pebble's throw of the beach</p>");
  break;
case "foodies":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 6;
  $j("#tabstrip li:nth-child(2)").addClass("active");
  //$j("h2#tenbesttitle").html("Baby-Friendly Properties for Food Lovers");
  $j("#tenbestcaption").html("<p>10 bolt-holes that are fabulous for foodies.</p>");
  break;
case "ecoaware":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 7;
  $j("#tabstrip li:nth-child(3)").addClass("active");
  //$j("h2#tenbesttitle").html("Eco-Aware Baby-Friendly Properties");
  $j("#tenbestcaption").html("<p>10 Eco-chic retreats..</p>");
  break;
case "funkyfarms":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 8;
  $j("#tabstrip li:nth-child(4)").addClass("active");
  //$j("h2#tenbesttitle").html("Funky Farm Baby-Friendly Properties");
  $j("#tenbestcaption").html("<p>10 funky farm stays</p>");
  break;
case "newparents":
  $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
  $j("#tabs1").hide();
  $j("#tabs2").show();
  $j("#currentpage").empty().html("2");
  selectNow = 9;
  $j("#tabstrip li:nth-child(5)").addClass("active");
  //$j("h2#tenbesttitle").html("Baby-Friendly Properties for New Parents");
  $j("#tenbestcaption").html("<p>10 bolt-holes that should come on prescription for new parent rejuvenation..</p>");
  break;
default:
  selectNow = 0;
  $j("#tabstrip li:first").addClass("active");
}
}
//alert(selectNow);

var $tabs = $j('#columnstabbed').tabs({ selected: selectNow }); // first tab selected
//$j($tabs).("disable");
//$j("#tab_bestrated").addClass("active");
//$j("#tabstrip li:first").addClass("active");
$j('#tabstrip li a').click(function() { // bind click event to link
$j("ul#tabstrip li").removeClass("active");
$j(this).parent().addClass("active");
return false;
});

$j($tabs).bind( "tabsselect", function(event, ui) {
  //window.location.hash = ui.tab.hash;
  $j("#tenbestcaption").hide();
  $j("#loading").loading({img: 'elements/images/loader.gif'});
  $j(".column_main").fadeOut(1200);
  $j("ul#tabstrip li").removeClass("active");
  $j(this).parent().addClass("active");
  //$j('.why, .whytext').css("width","330px");
  var tabClicked = ui.index;
  //alert(tabClicked);
 /* switch(tabClicked)
{
case 1:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that are terrific with toddlers...</p>");
  break;
case 2:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes we consider the most stylish in our collection...</p>");
  break;
case 3:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that are chic and economical...</p>");
  break;
case 4:
  $j("#tenbestcaption").show().html("<p>10 fabulously bolt-holes that provide parent-friendly romance..</p>");
  break;
  // second 'page' sections - these need to change the tabstrip as well
case 5:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that are ideal for sociable singles with little ones..</p>");
  break;
case 6:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes within a pebble's throw of the beach</p>");
  break;
case 7:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that are fabulous for foodies.</p>");
  break;
case 8:
  $j("#tenbestcaption").show().html("<p>10 Eco-chic retreats..</p>");
  break;
case 9:
  $j("#tenbestcaption").show().html("<p>10 funky farm stays</p>");
  break;
case 10:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that should come on prescription for new parent rejuvenation..</p>");
  break;
default:
  $j("#tenbestcaption").show().html("<p>10 bolt-holes that won the most consistently outstanding praise by BFB guests in 2010....</p>");
}*/
});
$j($tabs).bind( "tabsshow", function(event, ui) {
  $j('.why, .whytext').css("width","330px");
  Cufon.replace('#tenbestcaption');
});

/*$('#tabs').tabs({
    select: function(event, ui) {
        window.location.hash = ui.tab.hash;
    }
});*/




$j('a#tb2_more, a#tb2_more2').click(function() {
/*$j("#tabstrip").hide();
$j("#tabstrip2").show();*/
//var pagenumber = $j(this).html();
    var currentpage = $j("#currentpage").html();
    //alert (pagenumber);
    //alert(currentpage);
    //if(pagenumber!=currentpage) {
    $j("#tenbestcaption").hide();
    $j("#tabstrip").fadeOut(300);
    if(currentpage==1) {
    $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip2.png)");
    //$j('#tabstrip').load('../tenbest2_tabstrip2.php');
    $j("#tabs1").hide();
    $j("#tabs2, #tenbestcaption").show();
    $j("#tenbestcaption").html("<p>10 bolt-holes within a pebble's throw of the beach</p>");
    $j("#currentpage").empty().html("2");
    firsttab = 5;
    activetab = "sixth";
    /*$j("ul#tabstrip li").removeClass("active");
    $j("li#tab_singleparents").addClass("active");*/
    } else {
    $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip1.png)");
    //$j('#tabstrip').load('../tenbest2_tabstrip1.php');
    $j("#tabs2").hide();
    $j("#tabs1, #tenbestcaption").show();
    $j("#tenbestcaption").html("<p>10 bolt-holes that won the most consistently outstanding praise by BFB guests in 2010...</p>");
    $j("#currentpage").empty().html("1");
    firsttab = 0;
    activetab = "first";
    /*$j("ul#tabstrip li").removeClass("active");
    $j("#tabstrip li:"+activetab).addClass("active");*/
    }
    $tabs.tabs( "option", "selected", firsttab );
    $j("#tabstrip").fadeIn(350).show();
    //}
});

$j('ul.paging li a').live('click', function() {
    //$j("#loading").loading({img: 'elements/images/loader.gif'});
    var pagenumber = $j(this).html();
    var currentpage = $j("#currentpage").html();
    //alert (pagenumber);
    //alert(currentpage);
    if(pagenumber!=currentpage) {
    $j("#tenbestcaption").hide();
    $j("#tabstrip").fadeOut(300);
    $j('#tabstrip').css("background-image", "url(../elements/images/tenbest2/tenbest_2_tabstrip"+pagenumber+".png)");

    if(currentpage==1) {
    $j("#tabs1").hide();
    $j("#tabs2, #tenbestcaption").show();
    $j("#tenbestcaption").html("<p>10 bolt-holes within a pebble's throw of the beach</p>");
    $j("#currentpage").empty().html("2");
    firsttab = 5;
    $j("#tabstrip li:sixth").addClass("active");
    } else {
    $j("#tabs2").hide();
    $j("#tabs1, #tenbestcaption").show();
    $j("#tenbestcaption").html("<p>10 bolt-holes that won the most consistently outstanding praise by BFB guests in 2010...</p>");
    $j("#currentpage").empty().html("1");
    firsttab = 0;
    $j("#tabstrip li:first").addClass("active");
    }
    $j("#tabstrip").fadeIn(350).show();
    $j("#currentpage").empty().html(pagenumber);
    $tabs.tabs( "option", "selected", firsttab );
    $j("ul.paging li").removeClass("active");
    $j(this).parent().addClass("active");
    }

    /*$j.ajax({
    type: "POST",
    url: "tb2tabs.php",
    cache: false,
    data: "pagenumber=" +  pagenumber,
    success: function(html){
    $j("#tabstrip").html(html).fadeIn(350).show();
    $j("#currentpage").empty().html(pagenumber);
    $j($tabs).("enable");
    $j("#tabstrip li:first").addClass("active");
    }
    });
    $j("ul.paging li").removeClass("active");
    $j(this).parent().addClass("active");
    }
    $j('#columnstabbed').tabs({ selected: 0 });*/


    return false;
});


//alert (currentHash);

//$j('#bfbcomments').cycle({fx: 'fade', timeout: 7500});
//});
//window.location = "#toptentitle";


//old style tenbest code - not relevant except for reference

/*function loadProperty(propertyCode) {
$j('.selected_image').animate({
opacity: 0
      }, 500 );
propertyid = propertyCode.replace('property','');
parentlist = $j('#topten_main').find('.fulllist.active').attr('id');
parentlistid = parentlist.replace('fulllist','');
//alert(parentlistid);
$j.ajax({
type: "GET",
url: "scripts/xhr_property_single.php",
cache: false,
data: "propertyid=" + propertyid + "&parentlistid=" + parentlistid,
success: function(html){
//alert(html);
propertydata = html.split("#");
$j('.fulllist.active .selected_image').html(propertydata[3]);
$j('.fulllist.active .selected_property h4').html(propertydata[0]);
$j('.fulllist.active .selected_why p.why_text').html(propertydata[9]);
if(propertydata[10]!="") {
$j('.fulllist.active p.quotes').html(propertydata[10]);
}
$j('.fulllist.active .excerpt_text').html(propertydata[7]);
//$j('.fulllist.active .listingenquire').html(propertydata[3]);
//$j('.fulllist.active a.booknow').attr("href", propertydata[8] + ".htm#availability");
$j('.fulllist.active a.moreinfo').attr("href", propertydata[8] + ".htm#property_details");
$j('.fulllist.active .selected_image').animate({
opacity: 1.0
      }, 750 );
$j(".fulllist.active ul.excerpt_list, .fulllist.active .listingenquire, .fulllist.active .selected_why, .fulllist.active .selected_property").show();
}
});
}
function loadBestList(listID) {
listid = listID.replace('list','');
block = "fulllist" + listid;
$j.ajax({
type: "GET",
url: "scripts/xhr_get_tenbest.php",
cache: false,
data: "listid=" + listid,
success: function(html){
listdata = html.split("---");
listName = listdata[0];
newList = "<ol>\n" + listdata[1] + "</ol>\n";
$j('.property_list').empty();
$j('.fulllist').hide();
$j('.fulllist, .standard_header').removeClass('active');
$j('#' + block).addClass('active').show();
$j('#' + listID).addClass('active').show();
$j('#' + block + ' .property_list').html(newList);
window.location = String(window.location).replace(/\#.*$/, "") + "#" + listID;
loadProperty(listdata[2])
}
});
}
$j(".standard_header").live("click",function () {
var listID = $j(this).attr("id");
loadBestList(listID);
});
$j(".property_list ol li").live("click",function () {
var propertyID = $j(this).attr("id");
loadProperty(propertyID);
});*/

$j("#tenbestcaption").show();
// end document.ready()
});
