// jquery.cookie.min.js
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};

$(document).ready(function () {


    var _isIE = /*@cc_on!@*/0;
    var _xhr = window.XMLHttpRequest ? 1 : 0;

    var _isSelectorAble = (document.querySelectorAll) ? 1 : 0;
    var _isGetClassAble = (document.getElementsByClassName) ? 1 : 0;

    var _isLteIE6 = /*@cc_on@*//*@if (@_jscript_version <= 5.6)1; /*@end@*/0;
    var _isIE6 = /*@cc_on@*//*@if (@_jscript_version == 5.6)1; /*@end@*/0;
    var _isLteIE7 = /*@cc_on@*//*@if (@_jscript_version <= 5.7)1; /*@end@*/0;
    var _isIE7 = (_isLteIE7 && window.XMLHttpRequest) ? 1 : 0;

    _isIE6 = (_isLteIE7 && !window.XMLHttpRequest) ? 1 : _isIE6;
    _isLteIE6 = (_isLteIE7 && !window.XMLHttpRequest) ? 1 : _isLteIE6;








    // open links in external window
    externalLinks();
    internalLinks();

    //funwith fab
    reset();
    var val;

    // jquery accordion panels Tour 2010
    $(".accordion div.acc-top:first");
    $(".accordion div.acc-btm").hide();

    $(".accordion div.acc-top").click(function () {
        $(this).next("div").slideToggle("800")
        .siblings("div.acc-btm:visible").slideUp("800");
        $(this).toggleClass("open");
        $(this).siblings("div.acc-top").removeClass("open");
    });
    $('div.acc-top').css('cursor', 'pointer');
    if ($(".vote_image").length > 0) {
        if ($(".vote_image a").length > 0) {
          
            $(".vote_image a").each(function () {

                displayImageBox(this);

            });

        }
        else {
            $(".vote_image").each(function () {


                displayImageBox(this);

            });
        }



    }
    function displayImageBox(_link) {

        var $$ = $(_link);
        var _image = $$.find("img");

        var _html = '<img src="' + $(_image).attr("src") + '" alt="" class="voteImageColourBox" />';
        $$.colorbox({ html: _html, width: '700px', height: '550px' });
    }
    /*if (_isIE6) {


    if ($(".recaptchaForm").length > 0) {
            
    if (getParam("reloaded").length > 0) {
            
    return false;

    }
    else {

    var random = Math.round(Math.random() * 100);
    var originalurl = window.location.href;
    var url = originalurl + "&reloaded=" + parseInt(random);
    $(".recaptchaForm").append("<a href='" + url + "' class='reload' style='height:1px; width:1px;'>&nbsp;</a>");
    $("a.reload").click();
                
            
               
    }


    }
    }*/
    // Vote
    var c = '';
    if ($.cookie('myfabland1')) {
        c = $.cookie('myfabland1');
    }
    $('.vote').each(function (index) {
        var id = $(this).find('a').attr('id').toString().replace('v', '');
        $(this).bind('click', function (event) {
            event.preventDefault();

//            if (($.cookie('myfabland1')) == 5) {
//                jAlert('Maximum number of votes has been reached!');
//            }
//            else {
                $.ajax({
                    type: 'post',
                    url: '/design-a-den/vote_ajax.php',
                    data: 'id=' + id,
                    success: function (resp) {


                        var newValue = Number($.cookie('myfabland1')) + 1;
                        $.cookie('myfabland1', newValue, { expires: 365 });
                        jAlert('Thank you for voting!');


                    }
                });
//            }
            return false;
        });
    });

    // Share
    $('.share a').each(function (index) {
        var id = $(this).attr('id').toString().replace('s', '');
        if (_isIE6) {

            $(this).attr("href", '/design-a-den/share.php?id=' + id);
            $(this).attr("target", "_blank");
        }


        $(this).click(function () {

            if (_isIE6) {

            }
            else {
                $(this).parent().colorbox({
                    innerWidth: '560px',
                    innerHeight: '700px',
                    iframe: true,
                    href: '/design-a-den/share.php?id=' + id

                });
            }

        });
    });

    // Textarea maxlength
    /*var onEditCallback = function(remaining){
    $(this).siblings('.charsRemaining').text("Characters remaining: " + remaining);
    if(remaining > 0){
    $(this).css('background-color', 'white');
    }
    }
    var onLimitCallback = function(){
    $(this).css('background-color', 'red');
    }
    $('textarea[maxlength]').limitMaxlength({
    onEdit: onEditCallback,
    onLimit: onLimitCallback,
    });*/
    // lightbox

    if ($(".gallery a").length > 0) {

        $(function () {
            $(".gallery a").lightBox();
        });
    }
    if ($(".gallery2 a").length > 0) {

        $(function () {
            $('.gallery2 a').lightBox();
        });
    }
    if ($(".gallery3 a").length > 0) {

        $(function () {
            $('.gallery3 a').lightBox();
        });
    }
});
/*function fixIframeHeight(height) {
    
    $("iframe").attr("height", height);
    //$.colorbox.resize();
    //$.colorbox.resize() 
}*/
function reload1(form){
    reset();
    val=form.numberChildren.options[form.numberChildren.options.selectedIndex].value;

    if (val==2) {
        $('div#child-2').show();
        $('div#childage-2').show();
    };
    if (val==3) {
        $('div#child-2').show();
        $('div#childage-2').show();
        $('div#child-3').show();
        $('div#childage-3').show();
    };
    if (val==4  || val== '4+') {
        $('div#child-2').show();
        $('div#childage-2').show();
        $('div#child-3').show();
        $('div#childage-3').show();
        $('div#child-4').show();
        $('div#childage-4').show();
    };
}

function reset(){
        $('div#child-2').hide();
        $('div#child-3').hide();
        $('div#child-4').hide();

        $('div#childage-2').hide();
        $('div#childage-3').hide();
        $('div#childage-4').hide();
    }
    
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];
    if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external")  anchor.target = "_blank";
    }
};

function internalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];
    if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "internal")  anchor.target = "_self";
    }
};
function getParam( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
		//alert(results[1]);
	  if( results == null )
	    return "";
	  else
	    return results[1];

	};


