$(document).ready(function () {

    //var CatalogSubCatID// = $.query.get('SubCatID');
    //var CatalogCategoryID
    var linkText

    /*validator = $('#wedding').validate();
    $('#wedding').submit(function () {
        $('.required').each(function () {
            if ($(this).val() == '') {
                $('#' + $(this).attr('id') + 'error').html('* This field is required');
                return false;
            }
        });
    });*/
    $('.validate').validate();
    //$("#top a").removeClass("cur");
    //$("#top a[href*='"+strUrl+"']").css("color","#864B2A");

    //$('#tabs').superfish({speed:'fast', delay:0, onBeforeShow: function(){$('#tabs li:eq(1) img').css('background','#fff');}});

    // FAQ Page
    $("#landing h1").click(function () {
        if ($('#landing div').get(0).className == "closed") {
            $("div.closed").animateClass('open', 'closed', 500);
        } else {
            $("div.open").animateClass('closed', 'open', 500);
        }
    });

    // 
    $("#leftback, #landingmain, #rightback").equalizeCols();
    $('#landtext1 p').eq(1).css('marginTop', '5px');
    $('#landtext2 p').eq(1).css('marginTop', '10px');
    $('#landtext3 p').eq(1).css('marginTop', '7px');
    $('#landtext4 p').eq(1).css('marginTop', '7px');

    $("div.data").hide(); // hides all faqdata divs at start

    $("#forward-form").hide();

    $('#frontimg').click(function () { window.location = "/search.asp" });


    // tabs =========================================================

    //CatalogSubCatID = $.query.get('SubCatID');
    URL = location.pathname;

    $('#tabs li').click(function () {
        //$('#tabs li:eq(1) img').css('background','#D8E4EF');
    });
    $('#tabs li ul').hide();
    $('#tabs li').hover(
		function () {
		    $(this).children('ul').show(50);
		},
		function () {
		    $(this).children('ul').hide(50);
		}
	);

    if ($('.productsubnav').length > 0) {
        switch (CatalogSubCatID) {
            case '1':
                $('a[@href$="/search.asp?SubCatID=1"].productsubnav').css('color', '#EB008C');
                //console.log('here');
                break;
            case '15':
                $('a[@href$="/search.asp?SubCatID=15"].productsubnav').css('color', '#EB008C');
                break;
            case '3':
                $('a[@href$="/search.asp?SubCatID=3"].productsubnav').css('color', '#EB008C');
                break;
            case '6':
                $('a[@href$="/search.asp?SubCatID=6"].productsubnav').css('color', '#EB008C');
                break;
            case '17':
            	$('a[@href$="/search.asp?SubCatID=17"].productsubnav').css('color','#EB008C');
            	break;
        	default:
                //alert(CatalogSubCatID);
        }
    }

    if (1 == 2) {
        if (URL == '' || URL == '/default.asp') { $('#homelink').attr('src', $('#homelink').attr('src').replace('normal', 'selected')) }
        if (URL == '/builder.asp') { $('#designlink').attr('src', $('#designlink').attr('src').replace('normal', 'selected')) }
        if (URL == '/search.asp' && location.href.indexOf("Mode=Type") < 0 && location.href.indexOf("CategoryID=2") < 0) { $('#designlink').attr('src', $('#designlink').attr('src').replace('normal', 'selected')) }
        if (location.href.indexOf("Mode=Type") > -1 || location.href.indexOf("CategoryID=2") > -1) { $('#packagedlink').attr('src', $('#packagedlink').attr('src').replace('normal', 'selected')) }
    }
    // end tabs ===================================================

    // png alpha support
    $(window).load(function () {
        //$.ifixpng('/mlnapp/img/1px.gif');
        //$('img[@src$=.png]').ifixpng();
    });

    $('.bannermid img').hide()
    $('.bannerleft').click(function () {
        $(this).parent().find('.bannermid img').toggle('slow');
    })

    // front page
    $('#categorybreakout div').hide();
    $('#frontcat li').click(function () {
        $('#frontcat li').css({ color: '#361C11' });
        $('#categorybreakout div').hide();
        linkText = $(this).attr('class');
        $('#categorybreakout').children().filter('.' + linkText).show();
        $(this).css({ color: '#F3429F' });
        $('#frontcat').height(120);
    });
    //$('#frontcat li').hover(function(){$(this).css({color:'#864B2A'});},function(){$(this).css({color:'#361C11'});});

    $('#frontcat li:not(:first)').css({ borderLeft: '1px solid #371C12' });
    $('.breakoutsub ul li:not(:first-child)').css({ borderLeft: '1px solid #F3429F' });


    //$('#front .frontslides div img').iunfixpng(); 

    // front page animation
    // =================================================
    $('#frontSlides').cycle({
        fx: 'fade',
        speed: 500,
        timeout: 6000,
        pause: 1,
        next: '#fsnext',
        prev: '#fsprev',
        slideExpr: 'img'
    });

    $("#create_caricature").hover(function () { $(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif")); }, function () { $(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif")); });

    $('#mypose').click(function () {
        $.cookie('MyPose', '1');
        //alert($.cookie('MyPose'));
    });

    $('#designlink').click(function () {
        $.cookie('MyPose', '');
    });





    // silhouettes
    // =================================================
    //$("#silslides img[@src$=.png]").ifixpng();
    $('#silslides').cycle({
        fx: 'scrollRight',
        speed: 500,
        timeout: 0,
        next: '#assetnext',
        prev: '#assetprev',
        after: onAfter
    });


    // detail
    // =================================================
    $('#detailslides').cycle({
        speed: 500,
        timeout: 4000,
        next: '#detailnext',
        prev: '#detailprev',
        after: function (currSlideElement, nextSlideElement, options, forwardFlag) {
            //console.log('rel: '+$(this).attr('rel'));
            $('#enlarge').attr('rel', $(this).attr('rel'));
        }
    });

    $('#enlarge').click(function () {
        openWindowLarge('/large.asp?picorder=' + $(this).attr('rel') + '&ProductID=' + ProductID)
    });

    $('#detail input.submit').hover(function () {
        $(this).css({ color: '#864B2A' });
    }, function () {
        $(this).css({ color: '#462414' });
    });

    $('.detailslidecontrol').mousedown(function () { $(this).attr('src', $(this).attr('src').replace('0', '1')) });
    $('.detailslidecontrol').mouseup(function () {
        var thisimage = $(this)
        setTimeout(function () {
            thisimage.attr('src', thisimage.attr('src').replace('1', '0'))
        }, 500);
        //alert(thisimage.attr('src'));
    });

    // =================================================

    // adjustments for landing pages
    switch (PageID) {
        case "164":
            $("#landtext1").css({ lineHeight: '100%', margin: '0 0 0 0' });
            $("#landtext1 p:first").css({ lineHeight: '110%', margin: '20px 30px 0 30px' });

            $("#landtext2 p:first").css({ marginTop: '25px' });

            $("#landtext3 p").css({ lineHeight: '130%' });
            $("#landtext4 p").css({ lineHeight: '100%' });
            break;

        case "167":
            $("#landtext1").css({ lineHeight: '100%', margin: '0 0 0 0' });
            $("#landtext1 p:first").css({ lineHeight: '120%', margin: '20px 30px 0 30px' });

            $("#landtext2 p:first").css({ marginTop: '25px' });
            $("#landtext2 p").css({ lineHeight: '120%' });

            $("#landtext3 p").css({ lineHeight: '130%' });
            $("#landtext4 p").css({ lineHeight: '130%' });
            break;

        case "165":
            $("#landtext1").css({ lineHeight: '100%', margin: '0 0 0 0' });
            $("#landtext1 p").css({ margin: '8px 27px 0 27px' });
            $("#landtext1 p:first").css({ margin: '23px 27px 0 27px' });

            $("#landtext2 p:first").css({ marginTop: '25px' });
            $("#landtext2 p").css({ lineHeight: '130%' });

            $("#landtext3 p").css({ lineHeight: '130%' });
            $("#landtext4 p").css({ lineHeight: '110%' });
            break;

    }

    $('.roll').hover(function () { $(this).attr('src', $(this).attr('src').replace('Off', 'On')) }, function () { $(this).attr('src', $(this).attr('src').replace('On', 'Off')) });

    // big graphic breadcrumbs
    // =================================
    if (($('#detail').length > 0 || $('#resultsgrid').length > 0) && CatalogSubCatID != 6 && CatalogSubCatID != 17) {
        //console.log('adding big breadcrumb');
        $('#wrapper').append('<div id="bigbreadcrumb" style="position:absolute; top: 200px; left: -125px; height: 467px; width: 103px; z-index: 999"><img src="/webimg/2011/Breadcrumbs-Choose-A-Design-On.png" height="467" width="103"></div>');
    }

    if ($('#posebuilder').length > 0) {
        //console.log('adding big breadcrumb');
        $('#wrapper').append('<div id="bigbreadcrumb" style="position:absolute; top: 200px; left: -125px; height: 467px; width: 103px; z-index: 999"><img src="/webimg/2011/Breadcrumbs-Create-Caricature-On.png" height="467" width="103"></div>');
    }
    if ($('#PreviewTextInput').length > 0) {
        //console.log('adding big breadcrumb');
        $('#wrapper').append('<div id="bigbreadcrumb" style="position:absolute; top: 200px; left: -125px; height: 467px; width: 103px; z-index: 999"><img src="/webimg/2011/Breadcrumbs-Add-Your-Message-On.png" height="467" width="103"></div>');
    }
    // end big graphic breadcrumbs
    // =================================


    $(".deletepose").click(function () {
        var agree = confirm("Are you sure you want to delete?");
        if (agree) {
            $.get('/input.asp', { Type: 'DeletePose', UserID: UserID, PoseID: $(this).attr('id'), nt: (new Date().getTime()) });
            $(this).parent().parent().remove();
            return false;
        }
        else {
            return false;
        }

    });

    $('.posename').click(function () {
        //alert($(this).val());
        $(this).parent().parent().find('.namestatus').hide();
        if ($(this).val() == 'please enter a name for this pose here') { $(this).val(''); }
    });
    $('.posename').change(function () {
        console.log('saving name...');
        if ($(this).val() != '') {
            //save posename to database
            console.log('ajaxing saving name...');
            $.get('/input.asp', { Type: 'NamePose', PoseName: $(this).val(), UserID: UserID, PoseID: $(this).attr('id').replace('posename', ''), nt: (new Date().getTime()) });
            console.log('showing status...');
            $(this).parent().parent().find('.namestatus').show('slow');
            console.log('hiding status...');
        }
    });


});



function onAfter(curr, next, opts) {
    var index = $(this).parent().children().index(this);
    //$('#prev')[index == 0 ? 'hide' : 'show']();
    //$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    //alert($(this).parent().eq(index).is('.asset5'));
    //alert($(this).is('.asset5'));
    if ($(this).is('.asset5')==true) {$('#sillabel').html('Couples');$('#sillabel').css('width','210px');}
    if ($(this).is('.asset2')==true) {$('#sillabel').html('Brides');}
    if ($(this).is('.asset4')==true) {$('#sillabel').html('Pregnant Women');}
    if ($(this).is('.asset6')==true) {$('#sillabel').html('Miscellaneous');}
    if ($(this).is('.asset1')==true) {$('#sillabel').html('Chic');}
}
