var htmlData;
var tabDefault = '';
var videoName = '';
var switchTo5x = true;
var vidPlayerContent = '';
var flag = false; //set flag

//Sys.Application.add_load(initialize);
function initialize() {
    //tab_content();
    
        select_checkboxes();
   
        transcript();
   
        productTranscript();

        product_select();
 
        faq();
   
        tooltip();
   
        treeview();
    
        video_navigation();
    
        initialize_activity_video();
    
        product_video();
   
        sublink();
    
        breadcrumb_update();
   
    print_page();
    resetTextbox();			
    selectTab(tabDefault);
    popup_closer();
    custom_dropdown();
    //floodLight_call();
    Titletag();
    //setShare();
    //flood_light();
}
//function flood_light() {
//    var cat = $('.FloodLightTag').val();
//    var type = $('.FloodLightTag').attr('title');
//    var axel = Math.random() + "";
//    var a = axel * 10000000000000;
//    $('.frameContent').html('<iframe title="doubleClick" src="http://fls.doubleclick.net/activityi;src=3232144;type=' + type + ';cat=' + cat + ';ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
//}


//Sunita- function for tab click event for skyword article search. ---STARTS---
function floodLight_call() { /*
    //alert("here");
    $("ul.tabs li a").click(function() {
        var tabName = $(this).attr('class');
        var href = $(this).attr('href');
        if (tabName != null) {
            if (tabName == "atHomeWtBounty" ) {
                var axel = Math.random() + "";
                var a = axel * 10000000000000;
                var tempFlood = $(this).attr('title') + a + '?';
                $('.frameContent').html('<iframe src="' + tempFlood + '" width="1" height="1" frameborder="0" style="display:none"></iframe>');
                //alert(tempFlood);
                var noScrpt = $(this).find('input').attr('value'); // $("ul.tabs li input").attr('class');// + a +'?';
                //alert(noScrpt);
                $('.frameContent').html('<iframe src="' + noScrpt + '"width="1" height="1" frameborder="0" style="display:none"></iframe>');
            }
            else {
                if (tabName == "aboutBounty" && href != "#tab1") {
                    //alert(href); 
                    var axel = Math.random() + "";
                    var a = axel * 10000000000000;
                    var floodScrpt = $(this).attr('title') + a + '?';
                    $('.frameContent').html('<iframe src="' + floodScrpt + '" width="1" height="1" frameborder="0" style="display:none"></iframe>');
                    //alert(floodScrpt);
                   
                }
            }
        }
    });    
   */
}
//   -----ENDS---

function Titletag() {

    $("ul.tabs li a").click(function() {
        var tabName = $(this).attr('class');
        var href = $(this).attr('href');
        //alert(tabName);
        if (tabName == "aboutBounty") {

            if (href == '#tab2') {
                //alert(href);ul.tabs li.active
                var title = $(".tab_container .HistoryTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
               // alert(title);
                $(".content-holder title").text(title);
            }
            if (href == '#tab3') {
                //alert(href);ul.tabs li.active
                var title = $(".tab_container .VideoCommTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
                // alert(title);
                $(".content-holder title").text(title);
            }
            if (href == '#tab4') {
            //alert(href);ul.tabs li.active
                var title = $(".tab_container .FAQTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
               // alert(title);
                $(".content-holder title").text(title);
            }
        }
        if (tabName == "atHomeWtBounty") {
            //alert(tabName);
            if (href == '#tab2') {
                //alert(href);
                var title = $(".tab_container .FoodSafetyTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
                 //alert(title);
                $(".content-holder title").text(title);
            }
            if (href == '#tab3') {
                //alert(href);ul.tabs li.active
                var title = $(".tab_container .ArtsCraftsTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
                // alert(title);
                $(".content-holder title").text(title);
            }
            if (href == '#tab4') {
                //alert(href);ul.tabs li.active
                var title = $(".tab_container .CleanHouseTitleTag").val(); // ; $("a.active-product .prodtitleID").val();
                // alert(title);
                $(".content-holder title").text(title);
            }
        }
    });   
    
}
function selectTab(tab_default) {
    /*Tabs*/
   
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:last").addClass('last'); //Set the border curve for last menu element
    var firstTab = null;
    if (tab_default != '') {
	 	
        $("ul.tabs li a span:contains('" + tab_default + "')").click();
        if (firstTab == null && tab_default.indexOf('#') > 0) {
            var tabNew = tab_default.split('#');
            tab_default = tabNew[0];
            firstTab = '#' + tabNew[1];
            
        } else {
            firstTab = $("ul.tabs li a span:contains('" + tab_default + "')").parent().attr('href');
        }
        if (tab_default == 'undefined') {
            firstTab = $("ul.tabs li:first a").attr('href'); //get the id of the first tab
        }
    }
    else {
	//alert(tab_default);
        //$(".tab_content:first").show(); //Show first tab content
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        firstTab = $("ul.tabs li:first a").attr('href'); //get the id of the first tab
    }
    if ($.browser.msie && parseInt($.browser.version) == 7) { //fix the link issue in IE7
        if (firstTab) {
            var ieTabs = firstTab.split('#');
            firstTab = '#' + ieTabs[1];
        }
    }
    $(firstTab).show(); //Show the contents of the first tab contents
   
    if (videoName != '') { //play video for commercials
        $('span.video_title:contains(' + videoName + ')').parent().trigger('click').trigger('mousedown');
    }

    /*$('.login-register-content ul.tabs li').click(function() {
    $(this).addClass("active").prev().addClass('right_bg'); //Add "active" class to selected tab
    $(this).find('span').wrap('<span />');
    });*/

    //On Click Event
    $("ul.tabs li").click(function() {
    //if ($('.article-search-bar').is(':visible')) { alert('exists');} else { alert('doesnt exist') };
        if (!$(this).hasClass('active')) { //To prevent click on an already active tab			
            $("ul.tabs li").removeClass("active right_bg").find("a span span").unwrap(); //Remove any "active" & "right_bg" class	
            $(this).addClass("active").prev().addClass('right_bg'); //Add "active" class to selected tab
            $(this).find('span').wrap('<span />');
            $(".tab_content").hide(); //Hide all tab content

            /*var tab_index = $(this).index();// Get the index of clicked Tab and...
            $('.tab_content:eq('+tab_index+')').fadeIn(); // ...Fade in the corresponding content*/

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            if ($.browser.msie && parseInt($.browser.version) == 7) { //fix the link issue in IE7
                var ieTab = activeTab.split('#')
                activeTab = '#' + ieTab[1];
            }
            $(activeTab).fadeIn(); //Fade in the active ID content
            
            //alert(activeTab.substr(4, activeTab.length));

            var $articleSearch = $('.article-search-bar input');
            $articleSearch.val($articleSearch.attr('title')); //Reset Search bar text with default

            if ($(".dropdown dd")) { //close the open dropdown on click of tabs
                $(".dropdown dd").hide();
            }
        }
        return false;
    });
    /*Tabs Ends Here*/
    
    //if buy now page, add the GA code onload
    var ga_url = $('.product-list-holder li a.active-product input').attr('title');
    if (typeof ga_url != 'undefined' && ga_url != false) {
        _gaq.push(['_trackPageview',ga_url]);
    }
  
    
}

/*function selectTab(tab_default) {
if (tab_default != '') {
$("ul.tabs li a span:contains('" + tab_default + "')").click();
}
}*/

function faq() {

    /*FAQ*/
    $('.answer').hide().find('span a[href=""], span a:not([href])').hide(); //Hide the answers by default & empty learn more links
    $('.faq').css('position', 'relative'); //Fix UI issue for IE7 causing the answers to stay static when scrolled
    $('.faq>a').click(function() {
        $(this).next().fadeIn(); //Show the immediate answer
        $('.close_answer').click(function() {
            $(this).parent().parent().fadeOut(); //hide the answer block		  
        });
    });
    /*FAQ Ends Here*/
   
}

function select_checkboxes() {

    /*Checkbox Select/Deselect*/
    $('.selectors .deselect').click(function() {
        $('.activity_container input:checkbox').each(function() {
            this.checked = false;
        });
    });
    /*Checkbox Select/Deselect Ends Here*/

    /*Checkbox to behave as Radio Buttons*/
    $('.activity_selector .activity_container:gt(0) input:checkbox').change(function() {
        $(this).parents('.activity_container').find('input:checkbox').not(this).each(function(idx, el) {
            el.checked = false;
        });
    });
    /*Checkbox to behave as Radio Buttons Ends here*/

}

function transcript() {

    /*Transcript for Video*/
    $('.transcript').click(function() {	//on click of transcript link
        $(this).closest('.panel_holder,.video-panel').hide(); //hide the current panel
        $('.panel-holder-transcript').fadeIn(); //show the transcript panel cwhich was hidden by default
        return false;
    });
    $('.link-back-transcript').click(function() { //on click of back to video link
        $('.panel-holder-transcript').hide(); //hide the transcript panel
        $('.panel_holder,.video-panel').fadeIn(); //show the previous screen containing the video
    });
    /*Transcript for Video Ends Here*/
   
}

function productTranscript(){

    var videoStatus = true; 
    var vid_content = $('.product-video').html(); //Code for flash video
    var link_text = $('.product-transcript').html(); //link content
    if($('.product-transcript-content').text()!='')
    $('.product-transcript').show().click(function(){
        if(videoStatus == true) { //if video is visible
            $('.product-video').html($('.product-transcript-holder').html());
            $('.product-transcript').html('<span>&laquo;</span>Back to the video');
            videoStatus = false;
        }
        else { 
            $('.product-video').html(vid_content);
            $('.product-transcript').html(link_text);
            product_video(); //activate the video player
            videoStatus = true;
        }
    });
    else {
        $('.product-transcript').hide();
    }


}

function product_select() {

    
    $('.popup_content').removeClass('prod-load-height'); //reset product details height onload
    $('.product-detail-holder').hide(); //To hide the details part by default
    $('.tooltip a').attr('title', ''); //Remove title attribute on mouseover
    $('.product-list-holder li a').bind('click', function() {	//Activate a product on mouseover, click & focus
        var prodId = $(this).children(".prodId").val();

        var prodTitle = $(this).children(".prodtitleID").val() // ; $("a.active-product .prodtitleID").val();
       
        $(".content-holder title").text(prodTitle);

        //alert('huiawye');
        var initialWidth = $(this).width(); //inital width of the image holder b4 expanding
        if ($('.product_panel_description').next().hasClass('product_options_container')) { //If this is a Buy Now Page

            var prodIndex = $(this).parent().index();
            getOptionDetail(prodId, prodIndex); //Fetch Options
            
            
            var axel = Math.random() + "";
            var a = axel * 10000000000000;
            if($(this).children(".flooadLightTagSrc").val()!= '')
            {
                 var floodLightSrc = $(this).children(".flooadLightTagSrc").val() + a +'?'; 
                // alert(floodLightSrc);
                 $('.frameContent').html('<iframe src="'+floodLightSrc+'" width="1" height="1" frameborder="0" style="display:none"></iframe>');
            }

        }
        else { //If this is a Product Landing Page
            //getProdDetail(prodId, '.product-detail-holder', 'product-detail.html'); //Fetch the Product Details
            getProdDetail(prodId, '.product-detail-holder', '/Pages/Product_Detail.aspx'); //Fetch the Product Details
        }
        


        $('.product-list-holder li a').removeClass('active-product').css('margin', '0'); //Reset active class for all products
        $(this).addClass('active-product').find('.product-name-right').width($(this).find('.product-name-left').width() + 13).css('float', 'none'); //Activate current product & set the text width & alignment across browsers
        if ($(this).width() > initialWidth) { //to prevent image shifting on expanding after click
            var shift_value = -1 * ($(this).width() - initialWidth) / 2;
            $(this).css({ 'margin-left': shift_value, 'margin-right': shift_value });
        }
    });
    
   
}

function getOptionDetail(prodId, prodIndex) {

//alert("In getOptionDetail");
    $('.product_options_panel:eq(' + prodIndex + ')').fadeIn().siblings().hide();

    var $this = $('.product-list-holder li a').find('input[value=' + prodId + ']').parent(); //find the current product
    $this.addClass('active-product').find('.product-name-right');
    document.getElementById('ctl00_ContentPlaceHolder1_hidSelectedID').value = prodId;

    $('.product_options_panel:eq(' + prodIndex + ')').find('input').live('click', function() {
        document.getElementById('ctl00_ContentPlaceHolder1_hidSelectedOption').value = $(this).val();
        $('.buy_options_panel').fadeIn();
        resizeTheHolder('.popup_content', '.content-holder');


    });
    
   
}

function getProdDetail(prodId, content_holder, fetch_url) {

    var loaderHtml = '<div class="loader"><img src="/en-US/assets/images/ajax-loader.gif" alt="Loading..."  /></div>';
    var prodUrl = fetch_url.split("aspx"); // Splitting from aspx.. this is for Security Issue
    var nprodUrl = prodUrl[0] + "aspx";
    $(content_holder).html(loaderHtml).fadeIn();
    //var fetch_url = "product-detail.html"
    $.ajax({
        url: nprodUrl,
        type: "POST",
        cache: true,
        data: ({ prodId: prodId }),
        dataType: "html",
        error: handleProdError,
        success: function(data) {
            $(content_holder).html(data);
            show_product_options_panel(); //to show the dynamically loaded radio button panel
            resizeTheHolder('.popup_content', '.content-holder');
            var $this = $('.product-list-holder li a').find('input[value=' + prodId + ']').parent(); //find the current product
            $this.addClass('active-product').find('.product-name-right').width($($this).find('.product-name-left').width() + 13).css('float', 'none');
            //initialize();
        }
    });
    
   
}

function show_product_options_panel() {

    //$('.product_options_contents li:first input').attr('checked', 'checked').parents('.product_options_panel').next('.buy_options_panel').fadeIn();
    $('.product-detail-holder').fadeIn().find('input').click(function() {
        $('.buy_options_panel').fadeIn();
        resizeTheHolder('.popup_content', '.content-holder');
    });
    
   
}

function handleProdError() {
    $(".product-detail-holder").html("<p style='text-align:center;'>The page you are trying to reach can not be accessed right now. Please try again later.</p>");
}

function tooltip() {

    /*Tool Tip Starts Here*/
    $('.tooltip').hover(function() {
        if ($(this).find('a').hasClass('active-product')) {
            this.tip = this.title; //setting title attribute to a new variable
            this.title = ""; //To prevent browser default tool tip
        }
        else {
            //setting overflow visible for parents so dat tool tip will show up beneath the menu
            $(this).parents('.content, .product_content').css('overflow', 'visible');
            $('.description_bg_top, .product_content').addClass('left'); //applying float left for alignment across browsers
            $(this).css('position', 'relative'); //setting the parent relative for the absolute tool tip inside
            this.tip = this.title; //setting title attribute to a new variable
            $(this).append( //create tool tip panel
					'<div class="tooltip-wrapper">'
					+ '<div class="tooltip-top"></div>'
					+ '<div class="tooltip-mid">'
					+ this.tip //previously fetched title attribute displayed
					+ '</div>'
					+ '<div class="tooltip-btm"></div>'
					+ '</div>'
					);
            this.title = ""; //To prevent browser default tool tip
            this.width = $(this).width();
            $('li.tooltip:last-child').addClass('lasttip'); //identify last product to change the tool tip arrow
            $('.tooltip-wrapper').css({ left: $(this).offsetLeft }).fadeIn(); //set position & show tool tip
        }
    },

			function() {
			    $(this).parents('.content, .product_content').css('overflow', 'hidden'); //reset the styles for parents
			    $('.tooltip-wrapper').remove(); //hide tool tip
			    this.title = this.tip; //reset the title attribute back
			}
		);
   
}

function treeview() {

    //Class 'plus' refers to 'li' that has child with it.
    //$('.tree-menu ul').hide();By default the child ul of 'plus' will be set to 'display:none'
    $('.tree-menu li span').attr('tabIndex', '0').click(function() { //Start first click function
        $(this).parent().children('ul').slideToggle();
        if ($(this).parent().hasClass('plus')) {
            $(this).parent().removeClass('plus').addClass('minus');
        }
        else if ($(this).parent().hasClass('minus')) {
            $(this).parent().removeClass('minus').addClass('plus');
        }
    }
	); //end click function
	
	
}

function video_navigation() {

    if ($('.video-player').length > 0) { // if page contains vid & comm player
        vidPlayerContent = $('.video-player').html(); //default code of the player
    }


    $('.videos_section .thumbnail_small a').click(function() { //when a video thumnail is clicked
        var collection = $("div.videos_section").find(".thumbnail_small a");
        $(".videos_section .thumbnail_small a").click(function() {
            var axel = Math.random() + "";
            var a = axel * 10000000000000;
            var index = $(collection).index($(this));
            //alert(index);
            if (index == 2) {
                $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=video521;cat=us_12723;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
                var title = $(".hidCom2Title").val();
                //alert(title);
                $(".content-holder title").text(title);
            }

            if (index == 3) {
                $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=video521;cat=us_12623;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
                var title = $(".hidCom3Title").val();
                //alert(title);
                $(".content-holder title").text(title);
            }
        });

        var tabTitle = document.title; //to retain the page title in IE
        $('.video-player').html(vidPlayerContent); //rewrite the code to prevent video hiding issue in IE
        $(this).parents('.panel').hide().next('.video-panel').fadeIn(); //hide the current panel & show the hidden video panel
        video_parse($(this)); //to fetch the links & pass to flash player & you tube button

        $('.video-playlist-panel').empty().html($(this).parent().hide().parents('.videos_section').html()); //Copy paste playlist to video panel

        $('ul.tabs li').click(function() { //when tab is clicked after video is active 
           // alert('1');

            $('.video-panel, .panel-holder-transcript').hide(); //hide the video & transcript
            $('.video-player').empty(); //empty the player to reload the contents on click agn
            $('.panel, .thumbnail_small').show(); //reset link to video landing page and show the previously hidden thumbnails
        });
        document.title = tabTitle; //to reset the page title in IE


        //            var title = $(".tab_container .hidVidTitle").val(); // ; $("a.active-product .prodtitleID").val();
        //            alert("huiyser");
        //            $(".content-holder title").text(title);


        var thumbnail_ga = $(this).attr('onclick'); //get the thumbnail GA for the video
        $('.link-back-transcript').attr('OnClick', '_gaq.push(["_trackPageview",' + thumbnail_ga + '])'); //set video GA for back button

        var transcript_ga = $(this).next('.hidden').find('input').val(); //get the transcript GA for the video
        $('.transcript').attr('OnClick', '_gaq.push(["_trackPageview",' + transcript_ga + '])'); //set transcript GA

        return false;
    });

    $('.video-playlist-panel .thumbnail_small a').live('click', function() {
    
        var tabTitle = document.title; //to retain the page title in IE
        video_parse($(this));  //to fetch the links & pass to flash player & you tube button	
        $('.thumbnail_small').show(); //Show all thumbnails
        $(this).parent().hide(); //Hide currently playing video thumbnail
        document.title = tabTitle; //to reset the page title in IE
        
        var thumbnail_ga = $(this).attr('onclick'); //get the thumbnail GA for the video
        $('.link-back-transcript').attr('OnClick','_gaq.push(["_trackPageview",'+thumbnail_ga+'])');//set video GA for back button
        
        var transcript_ga = $(this).next('.hidden').find('input').val(); //get the transcript GA for the video
        $('.transcript').attr('OnClick','_gaq.push(["_trackPageview",'+transcript_ga+'])'); //set transcript GA
        
        return false; //prevent anchor click
    });
    
   
}
    function video_parse(active_thumbnail) {
  
        var video_links_text = active_thumbnail.find('input').val();
        var v_links = video_links_text.split('|');  //v_links[0]=video link, v_links[1]=youtube availability (true/false), v_links[2]=transcript		

        initialize_about_bounty_video(v_links[0]); //pass video to jw player

        if (v_links[1] == 'true') //If youtube link exist
            $('.video-player-links-panel a.youtube').show(); //Pass the youtube link to button
        else
            $('.video-player-links-panel a.youtube').hide(); //Hide the youtube btn if link is empty

        if (v_links[2] == 'true') {
            $('.transcript').show();
            $('#transcript_content').html(active_thumbnail.next().html());
            $('#transcript_title').text(active_thumbnail.find('.video_title').text() + ' Transcript');
        }
        else {
            $('.transcript').hide();
        }
   
}

/*Initialize Flash Video Player for About Bounty Page*/
function initialize_about_bounty_video(video_src) {

    var flashvars = { file: video_src, autostart: 'true' };
    var params = { allowfullscreen: 'true', allowscriptaccess: 'never', wmode: 'transparent' };
    var attributes = { /*id:'player', name:'player'*/};
swfobject.embedSWF('/en-US/assets/flash/player.swf', 'video-player', '392', '243', '9.0.115', 'false', flashvars, params, attributes);

   
}

/*Initialize Flash Video Player for Product Video Page*/
function product_video() {

    $('.product-video').parents('#popup').addClass('color-panel'); //remove the white top borders
    var vid_path = $('.product-video input').val();
    var flashvars = { file: vid_path, autostart: 'true' };
    var params = { allowfullscreen: 'true', allowscriptaccess: 'never' };
    var attributes = { id: 'player', name: 'player' };
    swfobject.embedSWF('/en-US/assets/flash/player.swf', 'product-video-player', '355', '224', '9.0.115', 'false', flashvars, params, attributes);
   
}

function initialize_activity_video(activity_vid_path) {

    var flashvars = { file: activity_vid_path, autostart: 'true', backcolor: 'db511c', frontcolor: 'ffffff', lightcolor: 'ffffff' };
    var params = { allowfullscreen: 'true', allowscriptaccess: 'never', wmode: 'transparent' };
    var attributes = { id: 'player', name: 'player' };
    swfobject.embedSWF('/en-US/assets/flash/player.swf', 'activity-video-player', '225', '192', '9.0.115', 'false', flashvars, params, attributes);

   
}

function popupOpened() {

    $('a.return_home').attr('href','/'); //to close sitemap home link
    var popup_x = ($(window).width() - $('#popup').width()) / 2;
    //var popup_y = 90;//($(window).height() - $('#popup').height()) / 2;
    $('#popup').css({ 'display': 'block', 'left': popup_x, 'top': 90 });

    $('#overlay').fadeTo("fast", 0.5); //open the background veil

    $('.content-holder').css('visibility', 'visible');
    var popupheight = $('.content-holder').height();
    $(".popup_content").height(popupheight);
    $('.home-div, .product-video-container').parents('#popup').addClass('color-panel');
    initialize();
    if ($('.active-product')) { //onload of buy now page, activate product
        $('.active-product .product-name-right').width($('.active-product').find('.product-name-left').width() + 13).css('float', 'none');
    }
    /*tab_content();	
    product_select();
    tooltip();*/
   
}

function sublink() {

    $('.home-div, .product-video-container').parents('#popup').addClass('color-panel');//fix close button for colored divs
    $('.popup_content a[target=_self]').not('#olBreadCrumb li:first a').click(function(e) {
        e.preventDefault();
        var fetch_url = $(this).attr("href");
        //popupLoaded = true;
        getsubPage(fetch_url);
    });

 
}

function getsubPage(fetch_url) {

    if (!fetch_url) {
        return;
    }
    getPodPage(fetch_url);

  
}



function breadcrumb_update() {

    $('.breadcrumb ul li:last a').addClass('inactive').click(function() { //deactivate last link as text
        return false;
    });

    var extLink = window.location.href;
    if (extLink.indexOf('Online_List.aspx') > 0 || extLink.indexOf('OffLine_List.aspx') > 0 || extLink.indexOf('en_US/') > 0 || extLink.indexOf('en-US/') > 0) { //reload the home page
        //$('.product-online-panel').parents('.content').find('#olBreadCrumb li:first a').attr('href', '/');
        $('#olBreadCrumb li:first a').attr('href', '/');
        $('.return_home').attr('href', '/');
    }

    var tabcode = $('.breadcrumb').html(); //default tab code to reset on click of tab to prevent continuous update

    $('.expotv ul.tabs li a').click(function() {

        var tabClick = $(this).attr("rel");
        var url1 = $('.hdnBounty input').attr('value');
        var url2 = $('.hdnExtrasoft input').attr('value'); ;
        var url3 = $('.hdnBasic input').attr('value'); ;
        var url4 = $('.hdnQuiltedNaokin input').attr('value'); ;
        var url5 = $('.hdnSelectSize input').attr('value'); ;
        
        if (tabClick == "#tab1") {
            $('.expotv').find('iframe').attr('src', '/Pages/blank.htm');
            $('.frameReview').attr('src', url1);
        }
        else if (tabClick == "#tab2") {
            $('.expotv').find('iframe').attr('src', '/Pages/blank.htm');
            $('.frameExtrasoft').attr('src', url2);
        }
        else if (tabClick == "#tab3") {
            $('.expotv').find('iframe').attr('src', '/Pages/blank.htm');
            $('.frameBasic').attr('src', url3);
        }
        else if (tabClick == "#tab4") {
            $('.expotv').find('iframe').attr('src', '/Pages/blank.htm');           
            $('.frameQuiltedNapkin').attr('src', url4);
        }
        else if (tabClick == "#tab5") {
            $('.expotv').find('iframe').attr('src', '/Pages/blank.htm');
            $('.frameSelectsize').attr('src', url5);
        }
    });

    $('ul.tabs li a, .product-list-holder li a').not('.login-register-content ul.tabs li a').click(function() { //when tab is clicked
         //alert("2");
        var tabClick = $(this).attr("href");
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
       // alert(tabClick);

        if (tabClick == "#tab1") {
            $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=produ608;cat=us_12298;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
        } 
        
        if (tabClick == "#tab2") {
            $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=produ608;cat=us_12016;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
        } 
        
        if (tabClick == "#tab3") {
            $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=video521;cat=us_12189;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
        }

        if (tabClick == "#tab4") {
            $('.frameContent').html('<iframe src="http://fls.doubleclick.net/activityi;src=3232144;type=produ608;cat=us_12417;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
        }

        if (flag == true) { //if this is not the first click on tab,
            $('.breadcrumb').html(tabcode); //reset the tab code to remove the previous updations
        }
        if ($(this).parent().index() != 0 || $(this).parent().hasClass('tooltip')) { //if clicked tab is not the first tab || if product page since only product page has tooltip
            $('.breadcrumb ul li:last a').removeClass('inactive').click(function() { //add anchor tab to the last breadcrumb
                $('.tabs li:first a').trigger('click'); //when the newly created breadcrumb link is clicked, reset the tabs to first tab
            }).parent().parent().append('<li class="seperator new">></li><li class="new">' + $(this).text() + '</li>'); //update breadcrumb
            flag = true; //set the flag that the tab was clicked before
        }
    });

    /*Video page breadcrumb to set video title*/
    $('.thumbnail_small a').live('mousedown click', function() { //when video thumbnail is clicked
        if (vidFlag == true) { //if this is not the first click on tab,
            $('li.vidNew').remove(); //reset the tab code to remove the previous updations
        }
        else {
            var linktext = $('.breadcrumb ul li:last').text();
            $('.breadcrumb ul li:last').html('<a href="#">' + linktext + '</a>');
        }
        $('.breadcrumb ul li:last').parent().append('<li class="seperator vidNew">></li><li class="vidNew">' + $(this).find('.video_title').text() + '</li>');
        vidFlag = true;

        $('.tabs li a, .popup_close a, #overlay').click(function() { //if any tab is clicked, set the tab to default
            vidFlag = false;
            $('li.vidNew').remove();
            $('.breadcrumb ul li:last a').addClass('inactive');
        });
        $('.breadcrumb ul li a:contains("Commercials and Videos")').click(function() { //activate breadcrumb link for videos
            $('.tabs li a:contains("Commercials and Videos")').click();
        });
    });





}


function resizeTheHolder(maindiv, heightDiv) {

    $("" + maindiv).each(function() {
        $(this).animate({ height: $('' + heightDiv).height() }, 500, function() {
            $('' + heightDiv).css('visibility', 'visible');
        });
    })
   
}
function print_page() {

    $('a.print').live('click', function(e) {
        e.preventDefault();
        window.open($(this).attr('href'), "Print", "status = 1, height = 792, width = 612,scrollbars=yes, resizable = 0");
    });
    
    
}

/*function setShare() {
    $.getScript('http://w.sharethis.com/button/buttons.js', function() {
        try {
            stLight.options({ publisher: '1b76cc44-3c82-4a58-ab65-4f068fa5b2c9', excludeServices: 'google,yahoo,linkedin' });
            //stLight.options({publisher:'1b76cc44-3c82-4a58-ab65-4f068fa5b2c9',offsetLeft:'10',excludeServices:'google,yahoo,linkedin'});
        } catch (e) {
            //do nothing
        }
    });
}*/


/*Extend jQuery to include the URL parameter function*/
$.extend({
    getUrlVars: function() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name) {
        return $.getUrlVars()[name];
    }
});
/////////***************USAGE********************////////
// Get object of URL parameters
// var allVars = $.getUrlVars();
// Getting URL var by its name
// var byName = $.getUrlVar('name');

/*****************URL parameter config ends here*********/

function popup_closer() { //To close popup on click of links other than close button, add a 'return_home' class

    $('#olBreadCrumb li:first a, .return_home').click(function() {
        //$('.product-online-retailers').parents();
        $('#overlay').trigger('click');
    });
    $('#olBreadCrumb li:first a, .return_home').live('click', function() {
        $('#overlay').trigger('click');
    });
    /*$('.return_home, #olBreadCrumb li:first a').removeAttr('target').live('click', function(e) {
    alert('clk');
    e.preventDefault();
    $('#overlay').trigger('click');
    return false;
    });*/


   
}


function custom_dropdown() {

    var $dropdownWrapper = $('.dropdown_content_wrapper');
    $(".dropdown dt a").click(function() {
        $(".dropdown dd").toggle();

        if ($('.dropdown_content').height() >= $dropdownWrapper.height()) { //if contents are less than holder
            $('.dropdown_bottom').addClass('no_overflow'); //remove bottom arrow
        }
        else {
            $('.dropdown_bottom').removeClass('no_overflow'); //add bottom arrow
        }
    });
    $(".dropdown dd ul li a").click(function() { //when dropdown element is clicked
        var text = $(this).html();
        $(".dropdown dt a span").html(text); //set the selected value as dropdown text
        $(".dropdown dd").hide(); //hide the expanded dropdwon
        return true;
    });
    $(document).bind('click', function(e) { //if clicked anywer outside the dropdown...
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown")) //clicked area is outside dropdown
            $(".dropdown dd").hide(); //hide the dropdown
    });

    $('.dropdown_bottom span').live('mousedown', function() { //when clicked on bottom arrow
        $('.dropdown_top').slideDown(); //show the top arrow
        $('.dropdown_content_wrapper').animate({ //move down the dropdown contents
            top: -1 * ($('.dropdown_content_wrapper').height() - $('.dropdown_content').height())
        }, 3000,function(){
            $('.dropdown_bottom').addClass('no_overflow'); //when completely scrolled, hide bottom arrow
        });
    });

    $('.dropdown_bottom span, .dropdown_top').bind('mouseup mouseout', function() { //on mouse up of arrows..
        $('.dropdown_content_wrapper').stop(); //stop scroll
    });

    $('.dropdown_top').live('mousedown', function() { //when top arrow clicked...
        $('.dropdown_bottom').removeClass('no_overflow'); //show bottom arrow
        $('.dropdown_content_wrapper').animate({ //move up the dropdown contents
            top: 0
        }, 3000, function() {
            $('.dropdown_top').slideUp(); //when completely scrolled, hide the top arrow
        });
    });

   
}

function breadcrumbOnload(currentProdID) {

    if (currentProdID) {
        var breadText = $('.product-list-holder li a input[value=' + currentProdID + ']').parent().text();
        var breadcode = $('.breadcrumb').html();

        $('.breadcrumb ul li:last a').removeClass('inactive').click(function() { //add anchor tab to the last breadcrumb
            $('.tabs li:first a').trigger('click'); //when the newly created breadcrumb link is clicked, reset the tabs to first tab
        }).parent().parent().append('<li class="seperator new">></li><li class="new">' + breadText + '</li>'); //update breadcrumb

        var breadClicked = false;
        $('.product-list-holder li a').click(function() {
            if (breadClicked == false) {
                $('.breadcrumb').html(breadcode);
                flag = false;
                breadcrumb_update();
                breadClicked = true;
            }
        });
    }

   
}
