function replacePNG(){
	$('img').each(function(){
		pngSRC = $(this).attr('src').split('.png');
		pngHeight = $(this).height();
		pngWidth = $(this).width();
		if(pngSRC.length > 1){
			$(this).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $(this).attr('src') + "', sizingMethod='crop')")
			$(this).attr('src', '/static/images/blank.gif').attr('width', pngWidth).attr('height', pngHeight);
		}
	});
}

function faqInit(){
	$('.faqType li div').hide();
    $('.faqType li').each(function(e){
        $(this).hover(
            function(){
                $(this).css('background','#F2F2F2');
            },
            function(){
                if($(this).attr('class') != 'faqOn'){
                    $(this).css('background','none');
                }
            }
        );
        $(this).find('span:first').click(function(){
            var theFAG = $('.faqOn div:visible'); 
            $('.faqOn div:first').hide(400);
            $('.faqOn').css('background','none');
            $('.faqOn').removeClass('faqOn');
            $(this).parent().css('background','#F2F2F2');
            //$(this).css('background','url(images/arrows_small.png) 0 -79px no-repeat');
            $(this).parent().addClass('faqOn');
            $(this).next('div:first').not($(theFAG)).show(400);
        })
    });
}

function createScroll(){
	if($('#topBlock').size() <= 0){
		if($('#mainContents').height() >= 540){
			$('#mainContents').removeClass('scroll1').addClass('scroll2');
			//isSafari3 = false;
			//if(window.devicePixelRatio){
				//isSafari3 = true;
			//}
			//if(isSafari3 == false){
				$('.scroll-pane').jScrollPane({dragMaxHeight:30, scrollbarWidth:24, scrollbarMargin:10, reinitialiseOnImageLoad:false});
			//}
		}
		if($('.awards #mainContents').height() >= 350){
			$('#mainContents').removeClass('scroll1').addClass('scroll2');
			$('.scroll-pane').jScrollPane({dragMaxHeight:55, scrollbarWidth:52, scrollbarMargin:0, reinitialiseOnImageLoad:false});
		}
		if($('#stretchBox #mainContents').height() >= 390){
			$('#mainContents').removeClass('scroll1').addClass('scroll2');
			$('.scroll-pane').jScrollPane({dragMaxHeight:30, scrollbarWidth:24, scrollbarMargin:10, reinitialiseOnImageLoad:false});
		}
	}
	else{
		//var contentSize = $('#topBlock').outerHeight() + $('#midBlock').outerHeight() + $('#btmBlock').outerHeight();
		//if(contentSize >= 520){
		if($('#mainContents').height() >= 540){
			$('#topBlock').prependTo('#mainContentWrap');
			$('#btmBlock').appendTo('#mainContentWrap');
			$('#mainContents').removeClass('scroll1').addClass('scroll2');
			var newHeight = 509 - $('#topBlock').outerHeight() - $('#btmBlock').outerHeight();
			$('#mainContents').css('height', newHeight + 'px');
			if($('.recipeUploadForm').size() > 0){
				$('.scroll-pane').jScrollPane({dragMaxHeight:80, scrollbarWidth:53, scrollbarMargin:10, reinitialiseOnImageLoad:false});
			}
			else if($('.becomeAFriendForm').size() > 0){
				$('.scroll-pane').jScrollPane({dragMaxHeight:46, scrollbarWidth:43, scrollbarMargin:10, reinitialiseOnImageLoad:false});
			}
			else{
				$('.scroll-pane').jScrollPane({dragMaxHeight:30, scrollbarWidth:24, scrollbarMargin:10, reinitialiseOnImageLoad:false});
			}
		}
	}
}

function trackProduct(page){
	pageTracker._trackPageview('/RightNavigationBarClick');
	document.location.href = 'http://www.ellaskitchen.co.uk' + page;
}

function wwifr(){
	replaceText('h1', 'ellas', '/static/flash/', '', '', '', '', '', '-3', '1.4');
	replaceText('h2', 'ellas', '/static/flash/', '', '#FFFFFF', '#c60001', '', '', '-3', '1.4');
	replaceText('h3', 'ellas', '/static/flash/', '', '', '', 'underline', '', '-3', '1.4');
}

function dropDowns(){
	$('.mySelect').hide().each(function(e){
		$('<div class="selectMenu" style="z-index:' + (100 - e) + ';"><span>Please select</span></div>').insertBefore($(this));		
		$(this).parent().find('.selectMenu').append('<div class="selectMenuList" style="z-index:' + (100 - e) + ';"><div><ul></ul></div></div>');
		$(this).find('option').not(':first').each(function(){
			$(this).parent().parent().find('ul').append('<li>' + $(this).text() + '</li>');
		});
	});
	$('.selectMenu span').click(function(){
		$('.selectMenuList').hide();
		$(this).parent().find('.selectMenuList').show();
	})
	$('.selectMenuList li').click(function(){
		$(this).parent().parent().parent().parent().find('span').text($(this).text());
		$(this).parent().parent().parent().hide();
		$(this).parent().parent().parent().parent().parent().find('select').val($(this).text());
	});
	$('.selectMenu').mouseleave(function(){
		$(this).find('.selectMenuList').hide();
	});
}

$(document).ready(function(){
	bubbleHeight = $('#bubble div').height() + 42 + 'px';
	$('#bubble img').height(bubbleHeight);
	$('#bubble').height(bubbleHeight);
	$("input[type=file]").filestyle({ 
		image: "/static/images/browse.gif",
		imageheight : 31,
		imagewidth : 65,
		width : 150
 	});
	$('.file').wrap('<div class="textfield5"></div>');
	dropDowns();
	createScroll();
	$('#background').flash({swf:'/static/flash/clouds.swf', width:'100%', height:'768', hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{sun:sun}, params:{wmode:'transparent'}});
	$('#girl').flash({swf:'/static/flash/ellas_body.swf', width:134, height:208, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{colour:dressColour, waving:ellaWaving}, params:{wmode:'transparent'}});
	$('#girl2').flash({swf:'/static/flash/ellas_body.swf', width:134, height:208, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{colour:dressColour, waving:ellaWaving}, params:{wmode:'transparent'}});
	$('#girl3').flash({swf:'/static/flash/ellas_body.swf', width:134, height:208, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{colour:dressColour, waving:ellaWaving}, params:{wmode:'transparent'}});
	$('#girl4').flash({swf:'/static/flash/ellas_body.swf', width:134, height:208, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{colour:dressColour, waving:ellaWaving}, params:{wmode:'transparent'}});
	$('#danmark').flash({swf:'/static/flash/danmark.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	$('#norge').flash({swf:'/static/flash/norge.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	$('#sverige').flash({swf:'/static/flash/sverige.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	$('#uae').flash({swf:'/static/flash/uae.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	$('#uk').flash({swf:'/static/flash/uk.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	$('#usa').flash({swf:'/static/flash/us.swf', width:35, height:30, hasVersion:8, expressInstaller:'/static/flash/expressInstall.swf', flashvars:{}, params:{wmode:'transparent'}});
	faqInit();
	if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var ieversion=new Number(RegExp.$1)
        if(ieversion < 7){
            replacePNG();
        }
    }
});

window.onload=function(){
	wwifr();
}