﻿var ff = { 
FFF_page:'http://fashionfactsfolio.com/fff_facts.php',
init:function() {
if (!document.getElementById || !document.createTextNode){return;}
$(document.body).addClass("jsWorks");
	
// when loading fff_facts page from outside, body id is set by php, here one adds slideshow and deletes the cookie
if (location.toString().indexOf('fff_facts') != -1) {
	if (ff.cookie('loadF')) { ff.loadSlideShow(ff.cookie('loadF')); ff.cookie('loadF', '', {expires: -1}) } else { ff.loadSlideShow('footwear') };
};
//array has class names for links (li), should stay one-className-only!!!
$.each(["footwear","accessories","colour", "trends","shopping"],function(i,n) {
	$('.'+n).click(function() 
		{ if (location.toString().indexOf('fff_facts') != -1) {
				ff.loadFact(this); return false;
			} else {
				ff.cookie('loadF',n); 
				location = ff.FFF_page; return false;
			}
		})
});
	
$('div.aArea').each(function() {
		$(this).hover(function() {
		$(this).addClass('blockOver');
	}, function() {
		$(this).removeClass('blockOver');
	}).click(function() {
		a=$(this).find('a')[0];
		var h = a.getAttribute("href");  
		var tt = a.getAttribute("target"); //if target -> open in new window, cancel a proper click
		!tt ? location = h : window.open(h); return false;
	})
})

//defined in css; for applyPngSpan to work in ie --  make sure all a's have width/height explicitly defined
$('.menuCombo').find('a').each( function() { 
var id = document.body.getAttribute('id');
if ($(this).parent().is('.'+id)) { // delete href of current page, add span
		$(this).removeAttr('href');
		ff.applyPngSpan(id,this);
		if ($(this).css('backgroundImage') != 'none') {
			$(this).parent().addClass('noDivider').next().addClass('noDivider');
		}
	} else { // add class to remove li left border
		$(this).hover(function() {
			$(this).parent().toggleClass('over').next().toggleClass('over');
		},function() {
			$(this).parent().toggleClass('over').next().toggleClass('over'); 
		}
		)
	}
}).end().hover(function() {
		$(this).toggleClass('applyPng');
	},function() {
		$(this).toggleClass('applyPng'); 
	}
)

//works without css
$('.menuHideDividers').find('a[@href]').each( function() { 
var id = document.body.getAttribute('id');
if ($(this).parent().is('.'+id)) { // delete href of current page
		$(this).removeAttr('href');
		if ($(this).css('backgroundImage') != 'none') {
			$(this).parent().addClass('noDivider').next().addClass('noDivider');
		}
	} else { // add class to remove li left border
		$(this).hover(function() {
			$(this).parent().toggleClass('over').next().toggleClass('over');
		},function() {
			$(this).parent().toggleClass('over').next().toggleClass('over'); 
		}
		)
	}
})

//defined in css;  for applyPngSpan to work in ie --  make sure all a's have width/height explicitly defined
$('.menuPngDarken').find('a').each( function() { 
		ff.applyPngSpan(document.body.getAttribute('id'),this);
	}).end().hover(function() {
		$(this).toggleClass('applyPng');
	},function() {
		$(this).toggleClass('applyPng'); 
	}
)
	
if (document.body.getAttribute('id') == 'contact') {
		if (navigator.appVersion.match(/MSIE [0-6]\./)) { 
			$('#submitBtn').hover(function() { 
			$(this).toggleClass("over"); },function() {
			$(this).toggleClass("over"); });
		$('input').focus(function() {$(this).addClass('ieFocus')});
		$('textarea').focus(function() {$(this).addClass('ieFocus')})
		};
		if($.browser.safari) {
			$("input").addClass('safari');
			$("textarea").addClass('safari');
		}
// 		validate.js must be present
//add <br /> before both <label if not position: absolute (then:
//.next() changes to .next().next()
		$("#name").after("<label for=\"name\" class=\"error required\">Please enter your name!</label>");
		$("#email").attr('validate','email').after("<label for=\"email\" class=\"error\" validate=\"email\">Please enter a valid email address!</label>");
		$("input").focus( function() { 
			if($(this).next().is(':visible')) { $(this).next().hide('slow')}; }) ;
		$("#form1").validate({debug: false, focusInvalidElement: false});
}

if (document.body.getAttribute('id') == 'index') {
var so = new SWFObject("images/homeFlashText.swf", "slideShow1", "142", "48", "7", ""); so.addParam("quality", "high");so.write("homeFlashText");
}

if (document.body.getAttribute('id') == 'miva') {
	var titleStr = ($(document).attr('title'));
	var checkout = 'Checkout';
	var inv = 'Invoice';
	var basket = 'Basket';
	if (titleStr.indexOf(checkout) != -1 || titleStr.indexOf(inv) != -1) {
	$('#wrapper').addClass('checkout'); /* $('#content').css('padding-top', '8px'); */ }
	else { $('#wrapper').addClass('jsworks'); 
	}
	if (titleStr.indexOf(basket) != -1) {
	$('#bcont').remove(); $('#baskCheckout').find('span').remove();
	}
if (titleStr.indexOf('70') != -1) { //target only product page
	var tr = $('form tr:first'); 
	var i = $('input[@name=Quantity]').parents()[2];
	$(i).prev().remove().end().prev().remove(); 
	$('input[@src$=Bask.gif]').addClass('imgFixed');
}
}

},

loadFact: function(_this) { 
	var h = $(_this).attr('class');
	$('body').attr('id',h); 
	if (navigator.appVersion.match(/MSIE [0-6]\./)) { 
	var s = 500; } else { var s = 2000; }
	$("#articles").highlightFade({color:'#c7c7c7',speed:s,iterator:'sinusoidal'});
	ff.loadSlideShow(h);
	ff.pngSpanFix();
	return false;
},

pngSpanFix:function() { 
	if ($('.sPng').size()>0) { 
		$('.sPng').each(function() {
			$(this).parent().html($(this).html());
		})
		$('.menuPngDarken').find('a').each( function() { 
			ff.applyPngSpan(document.body.getAttribute('id'),this);
		})
	}
},

applyPngSpan:function(id,a) {
	var t = $(a);
	if (t.parent().is('.'+id)) {
	var w = t.css('width'); var h = t.css('height'); //need for ie (all)
			t.html('<span style=\'width:'+w+';height:'+h+';\' class=\'sPng\'>'+t.html()+'</span>');
	}
},

loadSlideShow: function(f) {
var so = new SWFObject(f+".swf", "slideShow1", "210", "230", "7", ""); so.addParam("quality", "high"); so.write("rightSlideshow");
},

cancelClick:function(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (e && e.stopPropagation && e.preventDefault){
			e.stopPropagation();
			e.preventDefault();
		}
},
cookie: function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toGMTString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
}

} // end of times
$(document).ready(ff.init);