﻿$(document).ready(function() {
	
	var config5 = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
		var ul = $(this).parent();
		$popup = $(this).find('div.popup');
		$popup.removeClass('popup-right').removeClass('popup-left');
	
		if((this.offsetLeft + ul[0].offsetLeft) > 190) {
			$popup.addClass('popup-right');
		} else {
			$popup.addClass('popup-left');
		}
		$popup.toggle();
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 300, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).find('div.popup').toggle();
      }    
	};
	
	
	$('.list > ul > li').hoverIntent(config5);
	$('.slider > ul > li').hoverIntent(config5);
	$('.itemsGrid > li').hoverIntent(config5);
	$('.itemsGrid li').hoverIntent(config5);
	$('.bottom li').hoverIntent(config5);

	
	
	var config4 = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
        $(this).find('ul').toggle();
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).find('ul').toggle();
      }    
	};
	
	$('.tabs > li').hoverIntent(config4);
	
	var config3 = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
        $(this).find('a:first').addClass('hoverF');
        $(this).find('ul').toggle();
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).find('a:first').removeClass('hoverF');
        $(this).find('ul').toggle();
      }    
	};
	
	$('.flashMenu > li').hoverIntent(config3);
	
	var config2 = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
        $(this).addClass('hoverLi');
        $(this).find('div:first').toggle();
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).removeClass('hoverLi');
        $(this).find('div:first').toggle();
      }    
	};
	
	$('#mainMenu > li').hoverIntent(config2);
	
    var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
        $(this).find('a:first').addClass('hovers');
        $(this).find('.choise').toggle();
        $(this).find('.choice').toggle();
        $('.ac_results').slideUp(300);
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 300, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).find('a:first').removeClass('hovers');
        $(this).find('.choise').toggle();
        $(this).find('.choice').toggle();
      }    
	};
	
	$('.selectDiv').hoverIntent(config);
	$('.selectDiv1').hoverIntent(config);
	
	$(".choise input").click(
	function() {
	 if ($(this).is(":checked")) 
	 {
	  	$('.selectDiv a').text($(this).next().text());
		$('.selectDiv').css('width',$('.selectDiv a').width()+31);
	 }
	});
	$(".choice input").click(
	function() {
	 if ($(this).is(":checked")) 
	 {
	  	$('.selectDiv1 a').text($(this).next().text());
		$('.selectDiv1').css('width',$('.selectDiv1 a').width()+31);
	 }
	});
	
	$('#mainMenu > li').each( function()
					{
						$(this).find('.hoverArrow').css('width',$(this).width());
					}
	);
	$('.selectDiv a').each( function()
					{
						$('.selectDiv').css('width',$(this).width()+31);
					}
	);

	$(function() {
		$("#carousel1 .slider").jCarouselLite({
			btnNext: "#carousel1 .next",
			btnPrev: "#carousel1 .prev",
            afterEnd: function(a)
            {
                $(a[0]).hoverIntent(config5);
                $(a[3]).hoverIntent(config5);
            }
		});
	});
	
	$(function() {
		$("#carousel1BestSeller .slider").jCarouselLite({
			btnNext: "#carousel1BestSeller .next",
			btnPrev: "#carousel1BestSeller .prev",
            afterEnd: function(a)
            {
                $(a[0]).hoverIntent(config5);
                $(a[3]).hoverIntent(config5);
            }
		});
	});
	
	$(function() {
		$("#carousel1Future_Release .slider").jCarouselLite({
			btnNext: "#carousel1Future_Release .next",
			btnPrev: "#carousel1Future_Release .prev",
            afterEnd: function(a)
            {
                $(a[0]).hoverIntent(config5);
                $(a[3]).hoverIntent(config5);
            }
		});
	});
	
	$(function() {
		$("#carousel2 .slider").jCarouselLite({
			btnNext: "#carousel2 .next",
			btnPrev: "#carousel2 .prev"
		});
	});

	$(function() {
		$("#carousel .slider").jCarouselLite({
			visible: 7,
			btnNext: "#carousel .next",
			btnPrev: "#carousel .prev"
		});
	});


	$(".list2 .mess").click(function () { 
      	$(this).parent().parent().find('.message').animate( {
				"height": "toggle", 
				"opacity": "toggle"},
				300); 
    });
	

//*****************************************************/
//AJH 2010/08/13: For some reason this event fires more 
//than once.I suspect it'sbeen included in some other 
//file but can't find it anywhere so I've removed it here
//*****************************************************/
/*
	$("#checkout .set2 .tooltip").hover(
	 function () {
	   
        $(this).parent().find('.popup').animate( {
				"opacity": "toggle" },
				300);
      }, 
      function () {
        $(this).parent().find('.popup').animate( {
				"opacity": "toggle" },
				300);
      }
    );
	
	$("#checkout .summary .quantity p span").hover(
      function () {
        $(this).parent().parent().find('.popup').animate( {
				"opacity": "toggle" },
				300);
      }, 
      function () {
        $(this).parent().parent().find('.popup').animate( {
				"opacity": "toggle" },
				300);
      }
    );

*/
	
	$(".myAccount").getLogin({element:'.myAccount'});

	$(".myAccount .submit").click(function() {
		$(".myAccount").setCookie();
  	});
	
	$("#logout").click(function(e) {
		$(".myAccount").deleteCookie();
		location.href = window.location;
		e.preventDefault();
	});

    RefreshContent();

	$('.tabs li a').live("click", function(e) {
	    
//	    if($(this).parent().parent().parent().attr('class')=='more'){
        if($(this).parent('li').parent().parent().attr('class').indexOf('more') != -1){
	        $(this).parent().parent().children().attr('style','font-weight: normal');
	        
            element_more = $(this).parent().parent().parent().parent().find('li.more');
            element_more.children().children().attr('style','font-weight: normal');
	        
	        $(this).parent().attr('style','font-weight: bold;');
	        
	        var previous_active_category_id = $(this).parent().parent().parent().parent().find('li.active').attr('categoryId');

            current_active = $(this).parent().parent().parent().parent().find('li.active');
            
            // If the current active tab is the 'More' tab, I do nothing:
            if(current_active.text().indexOf('More') == -1){

    			current_active.html('<a href="category_grid.html" title="">' + current_active.text() + '</a>');
			    current_active.removeClass('active');
			    current_active.attr('style', 'font-weight: normal');
                
                element_more = $(this).parent().parent().parent().parent().find('li.more');                        
                element_more.addClass('active');                
                
                element_more.removeClass('more');  
                element_more.addClass('more');  
                
                element_more.attr('style','font-weight: bold; background: transparent img/list_li_active_a.gif no-repeat scroll 0 0;');
                element_more.html(element_more.html().replace('<a href="category_grid.html" title="">More</a>', '<strong>More</strong>'));
                // The following three lines are for Internet Explorer compatibility, that set the attributes in different order and with different capitalization
                element_more.html(element_more.html().replace('<a title="" href="category_grid.html">More</a>', '<strong>More</strong>'));
                element_more.html(element_more.html().replace('<A title="" href="category_grid.html">More</A>', '<strong>More</strong>'));
                element_more.html(element_more.html().replace('<A title="" href="http://localhost/DressCircle/category_grid.html">More</A>', '<strong>More</strong>'));
                
            
            }
            
	        	        
            var previous_active_category_text = $(this).parent().parent().parent().parent().find('li.active').text()	        
            
            // Here I hide the panel for the previous category
            var panel_name_hidden = 'panel' + previous_active_category_id;
            var panel_category_hidden = document.getElementById(panel_name_hidden);
            if(panel_category_hidden != null){
                panel_category_hidden.style.display = 'none';
            }

            
	        var new_active_category_id = $(this).parent().attr('categoryId');	        
	        
//	        var new_style = 'font-weight: bold;';	        
//	        $(this).parent().attr('style', "font-weight: bold;");    	        	    
//	        $(this).parent().attr('style', new_style );	            
	        
	        
//	        $(this).parent().html($(this).parent().html().replace('<a href="category_grid.html" title="">','<a title="" href="category_grid.html"><strong>').replace('</a>','</strong></a>'));
	        
//	        $(this).parent().html(htmlBold);
	        var new_active_category_text = $(this).text();
	        
	        
	        // Here I show the panel for the new current category
	        var panel_name_visible = 'panel' + new_active_category_id;
            var panel_category_visible = document.getElementById(panel_name_visible);
            if(panel_category_visible != null){
                panel_category_visible.style.display = 'inline';                                
            }            
            
            // Now I make the new category the current one and viceversa.            
//            $(this).parent().parent().parent().parent().find('li.active').attr('categoryId', new_active_category_id) ;
            
//            $(this).parent().parent().parent().parent().find('li.active').attr('specialItems', new_specialItems) ;
//            $(this).parent().parent().parent().parent().find('li.active').attr('displayItems', new_displayItems) ;
//            $(this).parent().parent().parent().parent().find('li.active').attr('showSlider', new_showSlider) ;
            
//            $(this).parent().parent().parent().parent().find('li.active').html('<strong>' + new_active_category_text + '</strong>');
                       
//	        $(this).parent().attr('categoryId', previous_active_category_id);	        	        
//	        $(this).parent().attr('specialItems', previous_specialItems);
//	        $(this).parent().attr('displayItems', previous_displayItems);
//	        $(this).parent().attr('showSlider', previous_showSlider);
	        	        
//	        $(this).html(previous_active_category_text);
	                    
	    }
	    else{

		    if($(this).parent('li').attr('class') == '') {
                $(this).parent().parent().find('li.more').children().children().attr('style','');
                $(this).parent().parent().children().attr('style','font-weight: normal;');
                $(this).parent().attr('style','font-weight: bold;');
                element_more = $(this).parent().parent().parent().parent().find('li.more');
                element_more.removeClass('active');
                if(element_more.html() != null)
                {
                    element_more.html(element_more.html().replace('<strong>More</strong>','<a href="category_grid.html" title="">More</a>')); 
                    // The following line is for Internet Explorer compatibility, that set the attributes in different order and with different capitalization
                    element_more.html(element_more.html().replace('<STRONG>More</STRONG>','<A title="" href="category_grid.html">More</A>'));
                    element_more.children().children().attr('style','font-weight: normal');
                }
		    
			    current_active = $(this).parent().parent('.tabs').find('li.active');
			    current_active.html('<a href="category_grid.html" title="">' + current_active.text() + '</a>');

                var previous_active_category_id = current_active.attr('categoryId');
                var previous_specialItems= current_active.attr('specialItems');
                var previous_displayItems = current_active.attr('displayItems');
                var previous_showSlider = current_active.attr('showSlider')
		        var panel_name_hidden = 'panel' + previous_active_category_id;
                var panel_category_hidden = document.getElementById(panel_name_hidden);
                if(panel_category_hidden != null){
                    panel_category_hidden.style.display = 'none';
                    $('.list').children(".slider").css("overflow", "hidden");
                    $('.list').children(".slider").css("visibility", "visible");
                    $('.list').children(".slider").css("position", "relative");
                    $('.list').children(".slider").css("z-index", "2");                    
                    $('.list').children(".slider").css("left", "0px");                    
                    $('.list').children(".slider").css("width", "400px");
                    
                    $('.list').find(".narrow").css("margin", "0pt");
                    $('.list').find(".narrow").css("padding", "0pt");
                    $('.list').find(".narrow").css("position", "relative");
                    $('.list').find(".narrow").css("list-style-type", "none");
                    $('.list').find(".narrow").css("z-index", "1");
                    $('.list').find(".narrow").css("width", "1200px");
                    
                    $('.list').find(".narrow li").css("overflow", "hidden");
                    $('.list').find(".narrow li").css("float", "left");
                    $('.list').find(".narrow li").css("width", "90px");
                    $('.list').find(".narrow li").css("height", "186px");
                }
			
			    current_active.removeClass('active');
			
    			$(this).parent('li').addClass('active');
						
                var new_active_category_id = $(this).parent('li').attr('categoryId');
                var new_specialItems= $(this).parent('li').attr('specialItems');
                var new_displayItems = $(this).parent('li').attr('displayItems');
                var new_showSlider = $(this).parent('li').attr('showSlider')
                
                var panel_name_visible = 'panel' + new_active_category_id;
                var panel_category_visible = document.getElementById(panel_name_visible);
                
                
                
                if(panel_category_visible != null){
                    panel_category_visible.style.display = 'inline';
                }            
                $(this).parent('li').html('<strong>' + $(this).text() + '</strong>');
                
		    }
	    
	    }

    	e.preventDefault();        
	});
	



});

//    function makeCategoriesPanelsInvisible(){
////        var listOfPanels = new Array('2', '3', '4');
//        var index;
//        var panel_name_hidden;
//        var panel_category_hidden;
//        for(index=0; index<listOfPanels.length; index++)
//        {    
//            panel_name_hidden = 'panel' + listOfPanels[index];
//            panel_category_hidden = document.getElementById(panel_name_hidden);
//            if(panel_category_hidden != null){
//                panel_category_hidden.style.display = 'none';
//            }
//        }
//    }



// Handle login cookies (temporary for login pages)
jQuery.fn.setCookie = function() {
	document.cookie = "ds-login=1";
	$(".myAccount").getLogin({element:'.myAccount'});
};

jQuery.fn.deleteCookie = function() {
	document.cookie = "ds-login=";
};

jQuery.fn.getLogin = function() {
	var args = arguments[0] || {};
	var element = (args.element == undefined || args.element == null) ? "" : args.element;
	
	var search = "ds-login="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) {
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	}
        function RefreshContent()
        {
            var config5 = {    
            sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
            interval: 100, // number = milliseconds for onMouseOver polling interval    
            over:  function () {
                var ul = $(this).parent();
                $popup = $(this).find('div.popup');
                $popup.removeClass('popup-right').removeClass('popup-left');

                if((this.offsetLeft + ul[0].offsetLeft) > 190) {
                    $popup.addClass('popup-right');
                } else {
                    $popup.addClass('popup-left');
                }
                $popup.toggle();
                },  // function = onMouseOver callback (REQUIRED)    
                timeout: 300, // number = milliseconds delay before onMouseOut    
                out: function () {
                    $(this).find('div.popup').toggle();
                }    
	    };
	
	
	    $('.list > ul > li').hoverIntent(config5);
	    $('.slider > ul > li').hoverIntent(config5);
	    $('.itemsGrid > li').hoverIntent(config5);
	    	$('.itemsGrid li').hoverIntent(config5);

	
	
	    var config4 = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100, // number = milliseconds for onMouseOver polling interval    
         over:  function () {
            $(this).find('ul').toggle();
          },  // function = onMouseOver callback (REQUIRED)    
         timeout: 500, // number = milliseconds delay before onMouseOut    
         out: function () {
            $(this).find('ul').toggle();
          }    
	    };
    	
	    $('.tabs > li').hoverIntent(config4);
    	
	    var config3 = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100, // number = milliseconds for onMouseOver polling interval    
         over:  function () {
            $(this).find('a:first').addClass('hoverF');
            $(this).find('ul').toggle();
          },  // function = onMouseOver callback (REQUIRED)    
         timeout: 500, // number = milliseconds delay before onMouseOut    
         out: function () {
            $(this).find('a:first').removeClass('hoverF');
            $(this).find('ul').toggle();
          }    
	    };
	
	$('.flashMenu > li').hoverIntent(config3);
	
	var config2 = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over:  function () {
        $(this).addClass('hoverLi');
        $(this).find('div:first').toggle();
      },  // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function () {
        $(this).removeClass('hoverLi');
        $(this).find('div:first').toggle();
      }    
	}
//	if(returnvalue == "1") {
//		$(element).html('<p>Logged in as: <strong>Murray</strong></p><p>QUICK LINKS:</p><ul><li><a href="09_dc_generic_v1.html" title="">My Dashboard</a></li><li><a href="09_dc_generic_v1.html" title="">My Details</a></li><li><a href="09_dc_generic_v1.html" title="">My Orders</a></li><li class="m3"><a href="09_dc_generic_v1.html" title="">My Wish List</a></li><li><a href="' + window.location + '" title="" id="logout">Logout</a></li></ul>');
//	}
};

function showCheckoutHelpText(title) {
    //alert(title);
    var helpText = '';
    
    switch (title) { 
        case '1': 
            helpText = '<p>No, just complete your contact details and proceed to our easy two step checkout. </p>';
            break;
        case '2': 
            helpText = '<p>Registering an account allows you to save your payment information for quick checkout, easily manage all your account information like shipping address, password, save a wish list to share with friends and family, and have access to exclusive member offers and promotions.</p>';
            break;
        case '3': 
            helpText = '<p>Simply click the &#147;Forgotten your password?&#148; link adjacent to the LOGIN button to the left and your password will be emailed to your registered address.</p>';
            break;
        case '4': 
            helpText = '<p>You can pay securely using your debit or credit card, or by using PayPal. You can also pay with a Dress Circle Electronic Gift Voucher by entering your unique code at checkout.</p>';
            break;
        case '5': 
            helpText = '<p>You may send the items in your Shopping Cart to different shipping addresses - simply specify the name and shipping address of each recipient when you fill out the order form. If you check the &#147;Add gift-wrap/note&#148; box, you can have us wrap your gift. <br /> Please note that you must select &#147;Add gift-wrap&#148; to be eligible for a free gift note to your order. </p>';
            break;
        case '6': 
            helpText = '<p>Delivery costs vary depending on where the package needs to be shipped and of course the size and weight. Example: The following is the cost to ship 1 CD: <br/> United Kingdom:  &#163;1.40 <br />Europe: &#163;2.50 <br />Rest of The World: &#163;3.50 </p> <p>For more detailed information please contact us at shopping@dresscircle.co.uk</p>';
            break;
        case '7': 
            helpText = '<p>Items which are in stock will usually be dispatched within 24 hours Monday to Friday. Delivery for overseas varies depending on the country. Please note: When orders are shipped internationally, they may be subject to customs clearance and charges which can cause delays beyond original delivery estimates.</p>';
            break;
        case '8': 
            helpText = '<p>Please contact shopping@dresscircle.co.uk for an update on your order status.</p>';
            break;
        case '9': 
            helpText = '<p>You can cancel any orders which have not yet been dispatched by going to My Account, clicking on Your Orders and clicking Cancel adjacent to the relevant item(s). You can also email shopping@dresscircle.co.uk or call +44 0207 240 2227 to cancel an order. </p>';
            break;
        case '10': 
            helpText = '<p>We are happy to accept returns of unopened/unused merchandise. Please post the package to the address above, or contact shopping@dresscircle.co.uk. We strongly advise sending any items back to Dress Circle as RECORDED DELIVERY as we cannot be responsible for non-delivery of returned items.</p>';
            break;
        case '11': 
            helpText = '<p>In the unlikely event of us sending you an incorrect order or an item is faulty please return the item using a recorded delivery service and we will send you the correct one and refund you any postage charges you incur.  Please enclose a note quoting your order number, the nature of the fault, and specify why you are returning it. For more information contact shopping@dresscircle.co.uk or call +44 0207 240 2227.</p>';
            break;
        case '12': 
            helpText = '<p>The Dress Circle website is hosted on a secure server with every effort taken to safeguard your information. Credit card details are encrypted and stored behind secure firewalls to protect them from hackers and other malicious attacks.</p>';
            break;
        case '13': 
            helpText = '<p>We respect your privacy and will never give or sell your information to third parties. Your email address will be used to send you our regular newsletter and to contact you directly relating to any order queries. </p>';
            break; 
        case '14': 
            helpText = '<p>You can contact us at shopping@dresscircle.co.uk or +44 0207 240 2227</p>';
            break;
    }
    $(".answer").html(helpText);
}
