var flipflop=1;
var storedata;

function OnloadPage() {
    
    if ($.browser.msie) {
        $.ajaxSetup({
            cache: false
        });	//Configuring ajax
    }

    var auctionUpdateTime = 500; //700;
    var counterUpdateTime = 1000;

    var auctions = '';

    $('.auction-item').each(function() {
        var auctionId    = $(this).attr('id');
        var auctionTitle = $(this).attr('title');
        auctions = auctions + auctionId + '=' + auctionTitle + '&';
    });

    auctions = auctions.slice(0,-1);

    var GlobalVar = 0;

    setInterval(function() {
        if (auctions) {
            getStatusUrl = '/update_info_2.php?flp=' + flipflop;

            //alert(getStatusUrl+auctions );

            $.ajax({
                url: getStatusUrl,
                dataType: 'json',
                type: 'get',
                cache:false,
                timeout: 2000,
                data: auctions,
                global: false,
                success: function(data) {
                    storedata = data;

                    //alert(data);

                    $.each(data, function(i, item) {
                        auction_id = item.auction.id;
                        auction_price = item.auction.price;
                        auction_bidder_name = item.auction.username;

                        value=item.auction.value;
                        if (auction_bidder_name=="") {
                            auction_bidder_name="---"
                        }
                        if(value==""){
                            value="---";
                        }

                        var pip=document.getElementById('price_index_page_' + auction_id);

                        if (pip!=null &&  pip.innerHTML != auction_price) {
                            if (GlobalVar == 1) {
                                if ($('.history_auctionid').length) {
                                    if (auction_id==document.getElementById('history_auctionid').innerHTML) {
                                        var forhoverid = new Spry.Effect.Highlight('price_index_page_' + auction_id , {
                                            duration: 500,
                                            from:'#f79909',
                                            to:'#f8f6f3',
                                            restoreColor: '#FFFFFF'
                                        });
                                        var forhoverid2 = new Spry.Effect.Highlight('currencysymbol_' + auction_id , {
                                            duration: 500,
                                            from:'#f79909',
                                            to:'#f8f6f3',
                                            restoreColor: '#ffffff'
                                        });
                                    } else {
                                        forhoverid = new Spry.Effect.Highlight('price_index_page_' + auction_id , {
                                            duration: 500,
                                            from:'#f79909',
                                            to:'#fdfdfd',
                                            restoreColor: '#FFFFFF'
                                        });
                                        forhoverid2 = new Spry.Effect.Highlight('currencysymbol_' + auction_id , {
                                            duration: 500,
                                            from:'#f79909',
                                            to:'#fdfdfd',
                                            restoreColor: '#fdfdfd'
                                        });
                                    }
                                } else {
                                    forhoverid = new Spry.Effect.Highlight('price_index_page_' + auction_id , {
                                        duration: 500,
                                        from:'#f79909',
                                        to:'#fdfdfd',
                                        restoreColor: '#FFFFFF'
                                    });
                                    forhoverid2 = new Spry.Effect.Highlight('currencysymbol_' + auction_id , {
                                        duration: 500,
                                        from:'#f79909',
                                        to:'#fdfdfd',
                                        restoreColor: '#fdfdfd'
                                    });
                                }
                                forhoverid.start();
                                forhoverid2.start();
                            }
                            document.getElementById('price_index_page_' + auction_id).innerHTML = auction_price;
                            //document.getElementById('currencysymbol_' + auction_id).innerHTML = "&#0036;";
                            var vip=document.getElementById('value_index_page_' + auction_id);
                            if(vip){
                                vip.innerHTML=value;
                            }
                            //document.getElementById('value_index_page_' + auction_id).innerHTML = value;
                            var pb=$('#product_bidder_' + auction_id);
                            if(pb.length){
                                pb.html(auction_bidder_name);
                            }
                            //document.getElementById('product_bidder_' + auction_id).innerHTML = auction_bidder_name;
                            //fedora add for top bidder
                            topbidder=item.auction.topbidder;
                            var tb=$('#topbider_index_page_' + auction_id);
                            if(tb.length){
                                acls=tb.attr('class');
                                totalcount=0;
                                if(acls.indexOf('i4')>0){
                                    totalcount=4;
                                }else if(acls.indexOf('i3')>0){
                                    totalcount=3;
                                }
                                if(totalcount>0){
                                    bidderhtml="";
                                    $.each(topbidder,function(i,bitem){
                                        bidderhtml+='<li><a '+'href="'+bitem.bidder.userid+'">'+bitem.bidder.username+'</a></li>'+"\r\n";
                                        totalcount--;
                                        if(totalcount==0) return false;
                                    });
                                    for(i=totalcount-1;i>=0;i--){
                                        bidderhtml+='<li><a href="">---</a></li>\r\n';
                                    }
                                    tb.html(bidderhtml);
                                }
                            }
                        //fedora add for top bidder

                        } else {
                            pip=document.getElementById('price_index_page_' + auction_id);
                            if ($('.history_auctionid').length) {

                                if (auction_id==document.getElementById('history_auctionid').innerHTML) {
                                    if(pip!=null){
                                        document.getElementById('price_index_page_' + auction_id).style.backgroundColor = "#ffffff";
                                    }
                                } else {
                                    if(pip!=null){
                                        document.getElementById('price_index_page_' + auction_id).style.backgroundColor = "#FFFFFF";
                                    }
                                }
                            } else {

                                if(pip!=null){
                                    document.getElementById('price_index_page_' + auction_id).style.backgroundColor = "#FFFFFF";
                                }
                            }
                        }
                    });
                    GlobalVar = 1;
                },
                error: function(XMLHttpRequest,textStatus, errorThrown) {/*alert(textStatus+"--"+errorThrown);*/}
            });
        }
        if (flipflop==1) {
            flipflop = 2;
        } else if (flipflop==2) {
            flipflop = 1;
            //alert(storedata);
            ChangeCountdownData(storedata);
        }
    }, auctionUpdateTime);

    $('.bid-button-link').click(function() {
        $.ajax({
            url: $(this).attr('name'),
            dataType: 'json',
            success: function(data) {

                $.each(data, function(i, item) {
                    result = item.result.split("|");

                    if (result[0]=="unsuccess") {
                        if (result[1]==1) {
                            alert("You don't have sufficient free points in your account!");
                            return false;
                        } else {
                            if (confirm("Please recharge your bidaccount!")) {
                                window.location.href='buybids.php';
                            }
                        }
                    }

                    if (result[0]=="topbid") {
                        alert('You are currently the top bidder, and cannot make additional bids to outbid yourself.');
                    }

                    if (result[0]=="early") {
                        if (-1 != window.location.pathname.indexOf('productdetails.php')) {
                            alert('Bidding opens for all auctions within the last 5 minutes, you can place auto bidders if you will not be able to participate.');
                        } else {
                            if (confirm('Bidding opens for all auctions within the last 5 minutes, you can place auto bidders if you will not be able to participate. Click OK to go to the product page or cancel to remove this dialog.')) {
                                window.location.href='productdetails.php?aid='+item.auction;
                            }
                        }
                        //alert('Bidding opens for all auctions within the last minute, you can place auto bidders if you will not be able to participate in the last minute.')
                    }
                    
                    if (result[0]=="winLimitVolumn" || result[0]=="winLimitPrice" || result[0]=="winLimitProduct" || result[0] == "winLimitCategory") {
                        if (result[1]==1) {
                            alert(item.message);
                            return false;
                        } else {
                            if (confirm(item.message)) {
                                window.location.href='mywinlimits.php';
                            }
                        }
                    }

                    if (result[0]=="binOverage") {
                        alert('You have reached the BIN price, and no further bidding is permitted past the BIN retail price. This item is considered sold to you at the BIN. Thank you for particpating in our auctions!');
                    }

                    if (result[0]=='levelLimit') {
                        alert(item.message);
                        return false;
                    }

                    if (result[0]=="success") {
                        if (result[1]==1) {
                            obj = document.getElementById('free_bids_count');
                            objvalue = document.getElementById('free_bids_count').innerHTML;
                            if (obj.innerHTML!='0') {
                                obj.innerHTML = Number(objvalue) - 1;
                            }
                        } else {
                            var name = result[2] == 1 ? 'promo_bids_count' : 'bids_count';
                            obj = document.getElementById(name);
                            objvalue = document.getElementById(name).innerHTML;
                            if (obj.innerHTML!='0') {
                                obj.innerHTML = Number(objvalue) - 1;
                            }
                        }
                    }
                    if (result[0]=="buynow") {
                            alert("After using the Buy Now option, you cannot place new bids on this auction.");
                    }
                });
            },
            error: function(XMLHttpRequest,textStatus, errorThrown) { }
        });

        return false;
    });

    if ($('.productImageThumb').length) {
        setInterval(function() {
            auctionhisid = document.getElementById('history_auctionid').innerHTML;

            oldprice = document.getElementById('curproductprice').innerHTML;
            newprice = document.getElementById('price_index_page_' + auctionhisid).innerHTML;

            if (oldprice!=newprice) {
                getStatusUrl3 = 'updatehistory.php?aucid_new='+auctionhisid;
				//alert(getStatusUrl3);

                $.ajax({
                    url: getStatusUrl3,
                    dataType: 'json',
                    success: function(data) {
                        data1 = eval('(' + data.responseText + ')');
                        var table = $('#tab_history table');
                        table.children().find("tr:gt(0)").remove();
                        
                        var fontweight;
                        //alert(data.histories.length);
                        for (i=0; i<data.histories.length; i++) {

                            if (!$("#bid_price_"+i).length) {
                                var html = $('<tr><td id="bid_price_'+i+'" style="font-weight: bold;"></td><td id="bid_user_name_'+i+'" style="font-weight: bold;"></td><td id="bid_type_'+i+'" style="font-weight: bold;"></td></tr>');
                                table.append(html);
                            }

                            biddingprice = data.histories[i].history.bprice;
                            biddingusername = data.histories[i].history.username;
                            biddingtype = data.histories[i].history.bidtype;


                            if(i==0){
                                fontweight="bold";
                                $("#product_bidder_"+auctionhisid).html(biddingusername);
                            }else{
                                fontweight="normal";
                            }

                            $("#bid_price_"+i).html("$" + biddingprice);
                            $("#bid_price_"+i).css("font-weight", fontweight);
                            
                            $("#bid_user_name_"+i).html(biddingusername);
                            $("#bid_user_name_"+i).css("font-weight", fontweight);

                            if (biddingtype=='s') {
                                $("#bid_type_"+i).html("Single Bid");
                            //document.getElementById('bid_type_' + i).innerHTML = "Single Bid";
                            } else if (biddingtype=='b') {
                                //document.getElementById('bid_type_' + i).innerHTML = "AutoBidder";
                                $("#bid_type_"+i).html("AutoBidder");
                            } else if (bidding_type=='m') {
                                //document.getElementById('bid_type_' + i).innerHTML = "SMS Bid";
                                $("#bid_type_"+i).html("SMS Bid");
                            }
                            $("#bid_type_"+i).css("font-weight", fontweight);
                        }
						function updatehistory(){
							         if(i==0){
                                fontweight="bold";
                            }else{
                                fontweight="normal";
                            }

                            $("#bid_price_"+i).html("$" + biddingprice);
                            $("#bid_price_"+i).css("font-weight", fontweight);

                            $("#bid_user_name_"+i).html(biddingusername);
                            $("#bid_user_name_"+i).css("font-weight", fontweight);

                            if (biddingtype=='s') {
                                $("#bid_type_"+i).html("Single Bid");
                            //document.getElementById('bid_type_' + i).innerHTML = "Single Bid";
                            } else if (biddingtype=='b') {
                                //document.getElementById('bid_type_' + i).innerHTML = "AutoBidder";
                                $("#bid_type_"+i).html("AutoBidder");
                            } else if (bidding_type=='m') {
                                //document.getElementById('bid_type_' + i).innerHTML = "SMS Bid";
                                $("#bid_type_"+i).html("SMS Bid");
                            }
                            $("#bid_type_"+i).css("font-weight", fontweight);
                        }

                        //alert(data.myhistories.length);

                        if (data.myhistories.length>0) {
                            for (j=0; j<data.myhistories.length; j++) {
                                if(j==0){
                                    fontweight="bold";
                                }else{
                                    fontweight="normal";
                                }

                                biddingprice1 = data.myhistories[j].myhistory.bprice;
                                biddingusername1 = data.myhistories[j].myhistory.time;
                                biddingtype1 = data.myhistories[j].myhistory.bidtype;

                                //document.getElementById('my_bid_price_' + j).innerHTML = "$" +  biddingprice1;
                                $("#my_bid_price_"+j).html("$" +  biddingprice1);

                                $("#my_bid_price_"+j).css("font-weight", fontweight);

                                //document.getElementById('my_bid_time_' + j).innerHTML = biddingusername1;
                                $("#my_bid_time_"+j).html(biddingusername1);
                                $("#my_bid_time_"+j).css("font-weight", fontweight);

                                if (biddingtype1=='s') {
                                    $("#my_bid_type_"+j).html("Single Bid");
                                //document.getElementById('my_bid_type_' + j).innerHTML = "Single Bid";
                                } else if (biddingtype1=='b') {
                                    $("#my_bid_type_"+j).html("AutoBidder");
                                //document.getElementById('my_bid_type_' + j).innerHTML = "AutoBidder";
                                } else if (biddingtype1=='m') {
                                    //document.getElementById('my_bid_type_' + j).innerHTML = "SMS Bid";
                                    $("#my_bid_type_"+j).html("SMS Bid");
                                }
                                $("#my_bid_type_"+j).css("font-weight", fontweight);
                            }
                        }
                        $("#curproductprice").html(data.histories[0].history.bprice);

                        //changedatabutler(data,"dbut",data.butlerslength.length);
                        changedatabutler(data,"dbut",0);
                    //document.getElementById('curproductprice').innerHTML = data.histories[0].history.bprice;
                    },
                    error: function(XMLHttpRequest,textStatus, errorThrown) { }
                });

                //update saving
                var onlineperbidvalue=$("#onlineperbidvalue_text").val();
                var price=$("#price_text").val();
                var fprice=$("#fprice_text").val();
                var aucid=$("#aucid_text").val();

                //alert(price+"_"+fprice+"_"+aucid+"_"+onlineperbidvalue);

                $.ajax({
                    type:'POST',
                    url:'update_savingprice.php',
                    dataType:'json',
                    cache:false,
                    data:{
                        onlineperbidvalue:onlineperbidvalue,
                        aucid:aucid,
                        price:price,
                        fprice:fprice
                    },
                    success:function(data){
                        if(data.msg=='ok'){
                            var parent = $('#promoBids').parent(),
                                children = parent.children();
                                                        
                            parent.text(data.data.totbid+' Bids (')
                                  .append(children)
                                  .append('):');

                            $('#promoBids').text(data.data.totfreebids+' Promo Bids');
                            $("#placebidsamount").html(data.data.totbidprice);
                            $("#placebidssavingdisp").html(data.data.saving);
                            $("#placebidssaving").html(data.data.saving);

                            if ($('#BinPrice').length) {
                                $('#BinPriceDiscount').html('$'+data.data.totbidprice);
                                var total = parseFloat($('#BinTotal').html().replace('$',''));
                                var paid = parseFloat($('#BinPriceDiscount').html().replace('$',''));
                                var price = total - paid;

                                if (price < 1) {
                                    price = 0.01;
                                }

                                $('#BinPrice').html('$'+price.toFixed(2));
                            }

                            $('#promoBids').tinyTips('orange','title');
                        }                        
                    },
                    error:function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert(textStatus);
                    }
                }); 

            }
        }, counterUpdateTime);
    }

    $(".bookbidbutlerbutton").click(function() {
        //alert(document.getElementById('bookbidbutlerbutton').name);
        if (document.getElementById('bookbidbutlerbutton').name!="") {

            var bidbutstartprice = Number(document.bidbutler.bidbutstartprice.value);
            var bidbutendprice = Number(document.bidbutler.bidbutendprice.value);
            var totalbids = document.bidbutler.totalbids.value;

            if (bidbutstartprice=="") {
                alert("Please enter AutoBidder start price!");
                return false;
            }
            if (bidbutendprice=="") {
                alert("Please enter AutoBidder end price!");
                return false;
            }
            if (totalbids=="") {
                alert("Please enter AutoBidder bids!");
                return false;
            }
            if (totalbids<=1) {
                alert("Number of Bids must be a number bigger than 0");
                return false;
            }
            if (totalbids>50) {
                alert("Maximum bids for each AutoBidder is 50!");
                return false;
            }
            if (bidbutstartprice>=bidbutendprice) {
                alert("AutoBidder End Price must be bigger than Start Price");
                return false;
            }

            $.ajax({
                url: "addbidbutler.php?aid="+$(this).attr('name')+"&bidsp="+bidbutstartprice+"&bidep="+bidbutendprice+"&totb="+totalbids,
                dataType: 'json',
                success: function(data) {
                    var promobids = false;

                    if (undefined != data.promoBids) {
                        promobids = data.promoBids;
                        delete data.promoBids;
                    }

                    $.each(data, function(i, item) {                        
                        if (item.result) {
                            result = item.result.split("|");
                            if (result=="unsuccessprice") {
                                alert("BID FROM Value needs to be greater than the Current Auction Price!");
                            } else if (result=="winlimit") {
                                alert("You have exceeded a win limit which affects this auction, and therefore are unable to set auto bidders.");
                            } else if (result[0]=="unsuccess") {
                                if (result[1]==1) {
                                    alert("You don't have sufficient free points in your account!");
                                } else {
                                    alert("Please recharge your bidaccount!");
                                }
                            } else if (result[0]=="message") {
                                alert(result[1]);
                            } else if (result[0]=="buynow") {
                                alert("After using the Buy Now option, you cannot place new bids on this auction.");
                            } else if (result[0]=="max") {
                                alert("You already have 3 AutoBidders for this auction.\nYou can place a new one after consuming one fo them.");
                            }
                        } else {
                            document.bidbutler.bidbutstartprice.value="";
                            document.bidbutler.bidbutendprice.value="";
                            document.bidbutler.totalbids.value="";
                            document.getElementById('butlermessage').style.display='block';
                            changeMessageTimer = setInterval("ChangeButlerImageSecond()",3000);
                            changedatabutler(data,"abut",totalbids);
                        }
                    });

                    if (promobids) {
                        $('#promo_bids_count').text(parseInt($('#promo_bids_count').text()) - promobids);
                        if ($('#bids_count').text() != '0') {
                            $('#bids_count').text(parseInt($('#bids_count').text()) + promobids);
                        }
                    }
                },
                error: function(XMLHttpRequest,textStatus, errorThrown) { }
            });

            return false;
        }
    });
}

function DeleteBidButler(id, div_id) {
    $.ajax({
        url: url = "deletebutler.php?delid=" + id,
        dataType: 'json',
        success: function(data) {
            var promobids = false;

            if (undefined != data.promoBids) {
                promobids = data.promoBids;
                delete data.promoBids;
            }

            $.each(data, function(i, item) {
                result = item.result;
                if (result=="unsuccess") {
                    alert("Your BidBuddy is running you can't delete it!");
                } else {
                    placebids = document.getElementById('butlerbids_' + div_id).innerHTML;
                    if ($('.usefreebids').length && document.getElementById('useonlyfree').innerHTML == '1') {
                        objbids = document.getElementById('free_bids_count');
                        objbidsvalue = document.getElementById('free_bids_count').innerHTML;

                        if (objbids.innerHTML!='0') {
                            objbids.innerHTML = Number(objbidsvalue) + Number(placebids);
                        }
                    } else {
                        objbids = document.getElementById('bids_count');
                        objbidsvalue = document.getElementById('bids_count').innerHTML;
                        if (objbids.innerHTML!='0') {
                            objbids.innerHTML = Number(objbidsvalue) + Number(placebids);
                        }
                    }
                    changedatabutler(data,"dbut","");
                }
            });

            if (promobids) {
                $('#promo_bids_count').text(parseInt($('#promo_bids_count').text()) + promobids);
                if ($('#bids_count').text() != '0') {
                    $('#bids_count').text(parseInt($('#bids_count').text()) - promobids);
                }
            }
        },
        error: function(XMLHttpRequest,textStatus, errorThrown) { }
    });
    return false;
}

function ChangeCountdownData(resdata) {

    if (resdata && resdata!="") {
        data = resdata;

        $.each(data, function(i, item) {
            auction_id = item.auction.id;
            auction_time = item.auction.time;
            pausestatus = item.auction.pause;
            value=item.auction.value;            
            if (auction_time) {
                //alert(auction_time);
                if (auction_time=='0') {
                    document.getElementById('counter_index_page_' + auction_id).style.color = '#000000';
                    document.getElementById('counter_index_page_' + auction_id).innerHTML = "Ended";
                    document.getElementById('image_main_' + auction_id).onclick="";
                    document.getElementById('image_main_' + auction_id).name="";
                    document.getElementById('image_main_' + auction_id).onmouseover="";
                    document.getElementById('image_main_' + auction_id).onmouseout="";
                    document.getElementById('image_main_' + auction_id).src = "img/buttons/btn-sold_92.png";

                    if (item.auction.bidInfo) {
                        if(item.auction.bidInfo.free) {
                           $('#free_bids_count').text(item.auction.bidInfo.bids);
                        } else {
                            $('#bids_count').text(item.auction.bidInfo.bids);
                        }
                    }
                    
                } else if (pausestatus==1) {
                    document.getElementById('counter_index_page_' + auction_id).innerHTML = 'Pause';
                    document.getElementById('image_main_' + auction_id).src = "img/buttons/btn_placebid_92.png";
                    document.getElementById('image_main_' + auction_id).onclick="";
                    document.getElementById('image_main_' + auction_id).onmouseover="";
                    document.getElementById('image_main_' + auction_id).name="";
                    document.getElementById('image_main_' + auction_id).onmouseout="";
                } else {
                    if (auction_time<10) {
                        document.getElementById('counter_index_page_' + auction_id).style.color = '#E80000';
                        document.getElementById('counter_index_page_' + auction_id).innerHTML = calc_counter_from_time(auction_time);
                    } else {

                        document.getElementById('counter_index_page_' + auction_id).style.color = '#002356';
                        document.getElementById('counter_index_page_' + auction_id).innerHTML = calc_counter_from_time(auction_time);
                    }

//                    if(document.getElementById("blink_img")!=null){
//                        if(auction_time<=15){
//                            document.getElementById("blink_img").style.display='block';
//                        }else{
//                            document.getElementById("blink_img").style.display='none';
//                        }
//
//                    }
                }
            }
        });
    }
}

function showhide_auctype(value,type){
    if(type=='over'){
        document.getElementById('auction_type'+value).style.display = "block";

    }else if(type=='out'){
        document.getElementById('auction_type'+value).style.display = "none";
    }
}

(function($){
	$.fn.tinyTips = function (tipColor, supCont) {

		if (tipColor === 'null') {
			tipColor = 'light';
		}

		var tipName = tipColor + 'Tip';

		/* User settings
		**********************************/

		// Enter the markup for your tooltips here. The wrapping div must have a class of tinyTip and
		// it must have a div with the class "content" somewhere inside of it.
		var tipFrame = '<div class="' + tipName + '"><div class="content"></div><div class="bottom">&nbsp;</div></div>';

		// Speed of the animations in milliseconds - 1000 = 1 second.
		var animSpeed = 300;

		/***************************************************************************************************/
		/* End of user settings - Do not edit below this line unless you are trying to edit functionality. */
		/***************************************************************************************************/

		// Global tinyTip variables;
		var tinyTip,
                    tText;

		// When we hover over the element that we want the tooltip applied to
		$(this).hover(function(e) {

			// Inject the markup for the tooltip into the page and
			// set the tooltip global to the current markup and then hide it.
			$('body').append(tipFrame);
			var divTip = 'div.'+tipName;
			tinyTip = $(divTip);
			tinyTip.hide();

			// Grab the content for the tooltip from the title attribute (or the supplied content) and
			// inject it into the markup for the current tooltip. NOTE: title attribute is used unless
			// other content is supplied instead.
			if (supCont === 'title') {
				var tipCont = $(this).attr('title');
			} else if (supCont !== 'title') {
				var tipCont = supCont;
			}
			$(divTip + ' .content').html(tipCont);
			tText = $(this).attr('title') || $(this).data('title');
			$(this).attr('title', '');

                        if (tText) {
                            $(this).data('title',tText)
                        }

			// Offsets so that the tooltip is centered over the element it is being applied to but
			// raise it up above the element so it isn't covering it.
			var yOffset = tinyTip.height() + 2;
			var xOffset = (tinyTip.width() / 2) - ($(this).width() / 2);

			// Grab the coordinates for the element with the tooltip and make a new copy
			// so that we can keep the original un-touched.
			var pos = $(this).offset();
			var nPos = pos;

			// Add the offsets to the tooltip position
			nPos.top = pos.top - yOffset;
			nPos.left = pos.left - xOffset;

                        if (nPos.left < 0) {
                            nPos.left = 10;
                        } else if ((nPos.left + tinyTip.outerWidth()) > $(window).width()) {
                            nPos.left -= (nPos.left + tinyTip.outerWidth()) - $(window).width();
                        }

			// Make sure that the tooltip has absolute positioning and a high z-index,
			// then place it at the correct spot and fade it in.
			tinyTip.css('position', 'absolute').css('z-index', '1000');
			tinyTip.css(nPos).fadeIn(animSpeed);

		}, function() {

			$(this).attr('title', tText);

			// Fade the tooltip out once the mouse moves away and then remove it from the DOM.
			tinyTip.fadeOut(animSpeed, function() {
				$(this).remove();
			});

		});

	}

})(jQuery); 

/**
 * Index tooltips
 */
$(function() {
   $('#promoBidsDone,#promoBids,ul.nav-button img:visible,.auction-item p img').tinyTips('orange','title');

//   var payment = $('form[name=payment]');
//
//   if (payment.size()) {
//       payment.submit(function() {
//           var username = payment.find('input[name=username]'),
//           confirmed = payment.find('input[name=termsAgreed]'),
//           hasAccount = payment.find('input[name=hasAccount]:checked'),
//           category = payment.find('span#category').text(),
//           returned = false;
//
//           if (! confirmed.attr('checked')) {
//               alert('Please confirm you have read and understood the terms!');
//           } else if (hasAccount.val() == '1' && username.val() == '') {
//               alert('You forgot to enter your username for '+category+'!');
//           } else if (!hasAccount.size()) {
//               alert('Please select whether you have an account with '+category+'!')
//           } else if (hasAccount.val() == '0') {
//               alert('please register an account with '+category+' and input your '+category+' username here.');
//               payment.find('input[name=hasAccount][value=1]').attr('checked',true);
//           } else {
//               returned = true;
//           }
//
//           return returned;
//       })
//   }
});
