﻿$(document).ready(function() {
    $('.trackLink').each(function() {
        $(this).click(function() {
            var linkType = $(this).attr('target') == '_blank' ? 'e' : 'o';
            var linkName = $(this).attr('linkName') ? $(this).attr('linkName') : $(this).attr('text');
            var trackVars = $(this).attr('trackVars') ? eval('(' + $(this).attr('trackVars') + ')') : {};

            scj.omniture.trackLink(trackVars, { 'linkName': linkName, 'linkType': linkType }, this);

        });
    });
});

String.prototype.underscore = function() {
    return this.replace(/\s+/g, '_');
};

String.prototype.replaceSymbols = function(symbols) {
    var string = escape(this);
    if (!arguments.callee.RE) arguments.callee.RE = new RegExp('(\\' + symbols.join('|\\') + ')', 'g');
    string = string.replace(arguments.callee.RE, '');
    string = string.replace('%26', 'and');

    return string;
};

var scj = { 
            fonts: {
                    Dakota: {
                        src: '/swf/Dakota.swf'
                    },
                    HelveticaNueExtLght: {
                        src: '/swf/HelveticaNueExtLght.swf'
                    },
                    HelveticaUltraLight: {
                        src: '/swf/HelveticaUltraLight.swf'
                    },
                    HelveticaNeue35Thin: {
                        src: '/swf/HelveticaNeue35Thin.swf'
                    },
                    HelveticaNeue55Roman: {
                        src: '/swf/HelveticaNeue55Roman.swf'
                    },
                    HelveticaUltraLightTwo: {
                        src: '/swf/HelveticaUltraLightTwo.swf'
                    },
                    HelveticaNeue55Roman: {
                        src: '/swf/HelveticaNeue55Roman.swf'
                    },
                    BakervilleRegular: {
                        src: '/swf/baskervilleurw-reg.swf'
                    }

                }
};

scj.omniture = {
    firstTime: true,
    section: '',
    symbols: ['&#174;', '&#8482;', '&copy;', '&trade;', '&reg;', '%AE', '%3F', '%u2122', '&#153;'],
    clear: function() {
        s = s_gi(s_account);
        s.events = '';
        s.products = '';
        s.pageName = '';
        s.linkTrackVars = '';
        s.linkTrackEvents = '';

        for (i = 1; i < 51; i++) {
            s['prop' + i.toString()] = '';
            s['eVar' + i.toString()] = '';
        }

        return true;
    },
    format: function(name) {
        return name.underscore().replaceSymbols(scj.omniture.symbols).toLowerCase();
    },
    trackLink: function(obj, options, event) {
        try {
            //alert('Obj: ' + obj + '\n' + 'Options: ' + options + '\n' + 'Event: ' + event);
            var event = event || this;
            scj.omniture._updateVars(obj);
            options.linkName = scj.omniture.format(options.linkName);
            s.linkTrackVars = '';
            for (key in obj) {
                s.linkTrackVars += key + ',';
            }
            if (obj.events) s.linkTrackEvents = obj.events;
            s.tl(event, options.linkType, scj.omniture.format(options.linkName), event);
            s_objectID = '';
            scj.omniture.clear();
        } catch (e) {

        }
    },
    fireTag: function(obj, options) {
        //alert('Obj: ' + obj + '\n' + 'Options: ' + options);
        options = options || {};
        scj.omniture._updateVars(obj, options);
        s_code = s.t(); if (s_code) document.write(s_code);
        scj.omniture.clear();
        return false;
    },
    _updateVars: function(obj, options) {
        var options = options || { append: {} };
        for (key in obj) {
            if (key == "events") {//s.events shouldn't get escaped because it will convert whitespace and commas to something we don't want
                s[key] = obj[key];
            } else {
                s[key] = options.append[key] ? escape(scj.omniture.section + '_' + scj.omniture.format(obj[key])) : escape(scj.omniture.format(obj[key]));
            }
        }
    }
}


/* Added For Jquery Mouse Over start    */

function display_form(pos, id) {
    $('.share_this_site').css({ backgroundPosition: '0px' + ' ' + pos + '' });
    $("#submitBox").hide();
    $("#rssbox").hide();
    $('#' + id).show();

    if (id == 'rssbox') {

        setTimeout(function() {
            $('#rssbox').fadeOut();
            $('.share_this_site').css({ backgroundPosition: 'top left' });
        }, 12000);
    }
}
/*Added the below function for the rss fade-out in thankyou page at the bottom*/
function display_form_bottom(id) {
    $('#' + id).show();
    $('#morefunoptionsbox').css({ 'display': 'none' });
    if (id == 'rssbox_Bottom') {
        
        setTimeout(function() {
        $('#rssbox_Bottom').fadeOut();
        $('#morefunoptionsbox').css({ 'display': 'block' });
        $('.rss_Largeicn').css({ 'background': 'none' });        
        }, 12000);
    }
}

function openLink(className,attrName) {
    var attrLink = $('.'+className).attr(attrName);
    window.open(attrLink);
}
$(document).ready(function () {    

    $('#rssbox').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -52px' });
    });

    $('.thumb_like').click(function (e) {
        var idVal = this.id;

        $(this).toggleClass('islike');
        var islike;
        var holderIdValue = $(this).parent().parent().find(".thumbsupctrl").attr("holderidval");
        var likesCount = $(this).parent().parent().find('.like_counter').html();
        if ($(this).hasClass('islike')) {
            likesCount++;
            $(this).parent().parent().find('.like_counter').html(likesCount);
            $(this).css({ backgroundPosition: 'bottom left' });
            islike = "1";
        }
        else {
            likesCount--;
            $(this).parent().parent().find('.like_counter').html(likesCount);
            $(this).css({ backgroundPosition: 'top left' });
            islike = "0";
        }

        $.ajax({
            type: "POST",
            url: "../WebService/DSSS.asmx/UpdateLike",
            contentType: "application/json; charset=utf-8",
            data: '{id: "' + holderIdValue + '",isLike:"' + islike + '"}',
            dataType: "json",
            success: function (data, status) {

            },
            error: function (request, status, error) {

            }
        });

    });
    $('.sender_submit').click(function (e) {
        //Cancel the link behavior
        //e.preventDefault();
        if (Page_ClientValidate('vgrpShareThisSite')) {
            //hide the submit box on successful input
            $('#submitBox').hide();
            $('.share_this_site').css({ backgroundPosition: 'top left' });
            $('#thankYou').show();
            onThankyouShare();
            setTimeout(function () { $('#thankYou').fadeOut(); }, 3000);
        }

    });
    //if close button is clicked
    $('.stsClose').click(function (e) {
        //Cancel the link behavior 
        e.preventDefault();

        $('#submitBox').hide();
        $('.share_this_site').css({ backgroundPosition: 'top left' });

    });

    //if close button is clicked
    $('.stsCloseBottom').click(function (e) {
        //Cancel the link behavior 
        e.preventDefault();
        $('#messageboxmain').hide();
        $('#morefunoptionsbox').css({ 'display': 'block' });
        $('.mail_Largeicn').css({ 'background': 'none' });
    });

    $('.friendsname').live("keyup", function () {

        $('.current_friendsname').text(this.value);
    });
    $('.yoursname').live("keyup", function () {

        $('.senders_name').text(this.value);
    });

    $('#submitBox').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -26px' });
    });
    $('.mail_icn').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -26px' });
    });


    $('.mail_icn').mouseout(function () {
        if (document.getElementById('submitBox').style.display == 'none')
            $('.share_this_site').css({ backgroundPosition: 'top left' });
    });

    //Added the below function to change the color of the Email to grey in thankyou page

    $('.mail_Largeicn').mouseover(function () {
        $('.mail_Largeicn').css({ 'background': 'url(../images/Submit/sprit.png)', 'background-position': '-1px 27px' });
    });

    //Added the below function to change the color of the blog to grey in thankyou page
    $('.mail_Largeicn').mouseout(function () {
        if (document.getElementById('messageboxmain').style.display == 'block') {
            $('.mail_Largeicn').css({ 'background': 'url(../images/Submit/sprit.png)', 'background-position': '-1px 27px' });
        }
        else {
            $('.mail_Largeicn').css({ 'background': 'none' });
        }
    });

    $('.rss_Largeicn').mouseover(function () {
        $('.rss_Largeicn').css({ 'background': 'url(../images/Submit/sprit.png)', 'background-position': '-70px 27px' });
    });

    //Added the below function to change the color of the blog to grey in thankyou page
    $('.rss_Largeicn').mouseout(function () {
        if (document.getElementById('rssbox_Bottom').style.display == 'block') {
            $('.rss_Largeicn').css({ 'background': 'url(../images/Submit/sprit.png)', 'background-position': '-70px 27px' });
        }
        else {
            $('.rss_Largeicn').css({ 'background': 'none' });
        }
    });


    $('.rss_icn').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -52px' });
    });

    $('.rss_icn').mouseout(function () {

        $('.share_this_site').css({ backgroundPosition: 'top left' });
    });

    $('.facebook_icn').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -78px' });
    });

    $('.facebook_icn').mouseout(function () {

        $('.share_this_site').css({ backgroundPosition: 'top left' });
    });
    $('.twitter_icn').mouseover(function () {

        $('.share_this_site').css({ backgroundPosition: '0px -104px' });
    });

    $('.twitter_icn').mouseout(function () {

        $('.share_this_site').css({ backgroundPosition: 'top left' });
    });



    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function (e) {

        //Cancel the link behavior
        e.preventDefault();        
        $('.rcbWidth').removeClass('rcbScroll');           
        /*The below function opens 'official rules' popup*/
        openpopup("#dialog");



    });

    //if close button is clicked 
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();        
        $('.rcbWidth').addClass('rcbScroll');
        //current window url
        var locUrl = window.location.toString();
        //get the main page utl
        var pairs = locUrl.split("?");
        if (pairs.length > 1) {
            //set the main page utl to current window
            window.location = pairs[0];
        }
        $('#mask').hide();
        $('.window').hide();
    });


    /* pop up method*/

    /*code starts from here for gallery details page*/

    //read all query strings from URLs
    var urlParams = {};
    (function () {
        var e,
        d = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); },
        q = window.location.search.substring(1),
        r = /([^&=]+)=?([^&]*)/g;

        while (e = r.exec(q))
            urlParams[d(e[1])] = d(e[2]);
    })();

    //set the flash vars
    var flashvars = {};
    (function () {
        if (urlParams["candleholderid"] != null) {
            var candleholderid = urlParams['candleholderid'];
            var isCardSubmitted = '';
            var cardStatus = '';
            // alert(candleholderid);
            //validate the candleholderid and if it is valid, load flash popup
            $.ajax({
                type: "POST",
                contenttype: "application/xml; charset=utf-8",
                dataType: "xml",
                url: "/webservice/dsss.asmx/ValidateHolderID",
                data: { 'HolderID': candleholderid },
                success: function (xml) {
                    cardStatus = $(xml).find('Status').text();
                    //load the flash vars if the card is available and approved
                    flashvars.holderId = candleholderid;
                    flashvars.Status = cardStatus;
                    // default values loaded . this is for the case when user reaches this page by typing complete url or by link in mail
                    flashvars.Sortvalue = '0';
                    flashvars.Searchvalue = '';
                    flashvars.Itemvalue = '0';
                    loadPopup('#detailFlash');
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                    //alert('2.Inside ERROR function'); 
                    //alert(xmlHttpRequest.statusText);  
                    //alert(xmlHttpRequest.responseText);  
                    //alert(textStatus+' : '+errorThrown);  
                }
            });
        }
    })();
    //-------------------------------------------------------------------------------------
    function loadPopup(divID) {
        //<!-- Adobe recommends that developers use SWFObject2 for Flash Player detection. -->
        //			<!-- For more information see the SWFObject page at Google code (http://code.google.com/p/swfobject/). -->
        //			<!-- Information is also available on the Adobe Developer Connection Under "Detecting Flash Player versions and embedding SWF files with SWFObject 2" -->
        //			<!-- Set to minimum required Flash Player version or 0 for no version detection -->
        var swfVersionStr = "10.0.0";
        //			<!-- xiSwfUrlStr can be used to define an express installer SWF. -->
        var xiSwfUrlStr = "";
        //			var flashvars = {}; 
        flashvars.userData = "/swf/user_data/00000001/design.xml";
        flashvars.daeModel = "/swf/dae/glade_candle.dae";
        flashvars.detailMode = "true";
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.play = "true";
        params.loop = "true";
        params.wmode = "transparent";
        params.scale = "noscale";
        params.menu = "true";
        params.devicefont = "false";
        params.salign = "";
        params.allowscriptaccess = "sameDomain";
        params.allowFullscreen = "true";
        var attributes = {};
        attributes.id = "flashContent";
        attributes.name = "flashContent";
        attributes.align = "middle";
        swfobject.embedSWF(
				"/swf/glade_tiffany_design.swf", "flashContent",
				"1000", "575",
				swfVersionStr, xiSwfUrlStr,
				flashvars, params, attributes);


        //Get the A tag 
        var id = $(divID);

        //Get the screen height and width 
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen 
        $('#mask').css({ 'width': '100%', 'height': '100%' });

        //transition effect              
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width 
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center 
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(2000);
        //scrollLoad();
    };

    //select all the a tag with name equal to GalleryDesignModal
    $('a[name=GalleryDesignModal]').click(function (e) {

        //Cancel the link behavior
        e.preventDefault();

        //call flashvars
        //var id = $(this).children('img').attr('HolderID');
        flashvars.holderId = $(this).children('img').attr('HolderID');
        //flashvars.ImageURL = $(this).children('img').attr('src');

        flashvars.Sortvalue = srt_items.indexOf($('.dropdownState').val());
        var searchValue = $('.search').val();
        if (searchValue != "Enter name of person or design") {
            flashvars.Searchvalue = searchValue;
        }
        else {
            flashvars.Searchvalue = '';
        }

        // 0 gets the current item.this is corret
        flashvars.Itemvalue = '0';

        //alert(flashvars.HolderID + ',' + flashvars.ImageURL);
        //select the dropdown selected value
        //alert('dropdown selecte value:'+ $('select[name=ctl00$cphContentBody$srt_top]').val());
        //select the dropdown selected value
        //alert('dropdown selecte text:'+ $('select[name=ctl00$cphContentBody$srt_top] option:selected').text() );

        //Get the A tag 
        var id = $(this).attr('href');
        loadPopup(id);
    });



}); 

$(document).ready(function(){ 
	if($.browser.msie) { 
		// see if browser is IE
	
		$("input.sprited, input.pnumber").click(
			function () { //solve IE BG image bug partially
			$(this).css("background-position","100% 0");
		}).blur(
			function(){
			 $(this).css("overflow","hidden");
                        // $(this).css("background-position","0 0");
		});
	}
});


/* Added For Jquery Mouse Over start    */
/*The below function opens 'official rules' popup and is called in the click event of the 'official rules' anchor tag*/
function openpopup(obj) {
    
    var id = obj;

    //Get the screen height and width 
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    //$('#mask').css({ 'width': '100%', 'height': '100%' });
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect              
    $('#mask').fadeIn(1000);
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width 
    var winH = $(window).height();
    var winW = $(window).width();
    var scrollHeight = window.pageYOffset ||
    document.body.scrollTop ||
    document.documentElement.scrollTop;

    //Set the popup window to center 
    $(id).css('top', (winH / 2) - $(id).height() / 2 + scrollHeight);
    $(id).css('left', (winW / 2) - $(id).width() / 2);


    //transition effect
    $(id).fadeIn(2000);
    scrollLoad();
    //for Omiture Tracking 
    callOmniture();
}

function trackDesignAction(prop3Value) {
    var trackVars = { prop2: 'design_candle_holder', prop3: prop3Value };
    var options = { 'linkType': 'o', 'linkName': "design_candle_holder_" + prop3Value };

    scj.omniture.trackLink(trackVars, options, this);
}

function trackViewAction(action) {
    var options = { 'linkType': 'o', 'linkName': action };

    scj.omniture.trackLink({}, options, this);    
}

function trackPrint() {
    var trackVars = { prop8: 'print_design' };
    var options = { 'linkType': 'o', 'linkName': 'design_candle_holder_print_design' };

    scj.omniture.trackLink(trackVars, options, this);
}

function trackShare(share, lt) {
    var type = lt || 'o';
    var trackVars = { prop2: share };
    var options = { 'linkType': type, 'linkName': share };

    scj.omniture.trackLink(trackVars, options, this);
}
