/** transparent png ie fix **/
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {
  document.styleSheets[0].addRule('.transparent', 'behavior: url('+siteurl+'/js/iepngfix.htc)');
 }

//jQuery.noConflict();

(function($){
    $(document).ready(function(){
        // field background
         $('.field').each(function() {             
             $(this).wrap('<div class="fieldleft"><div class="fieldright">')
             if(!$(this).hasClass('left')) {
                 $(this).parents('.fieldleft').after('<div class="clear"></div>');
             }
         });
            $('#accordion').accordion(
            {
                active: false,
                header: '.ahead',
                navigation: true,
                event: 'click',
                fillSpace: false,
                animated: 'easeslide',
                collapsible: true,
                autoheight:false,
                alwaysOpen: false

            });
         //grey round box - fix width with background
         $('.greybox').each(function() {
             if($(this).find('h3').parents('.head').length<=0) $(this).find('h3').wrap('<div class="head">');
             $(this).find('.inside').wrap('<div class="border">');
             $(this).append('<div class="bottom"><div class="line"></div><div class="rightside"></div></div>');
         });
         
         //grey round box - flexable without background
         $('.greybox1').each(function() {
             $(this).find('.head').wrapInner('<div class="leftc"><div class="rightc"><div class="text">');
             $(this).find('.inside').wrap('<div class="border">');
             $(this).append('<div class="bottom"><div class="leftc"><div class="rightc"><div class="line"></div></div></div></div>');
         });

         //grey round box - flexable without background
         $('.orangebutton, .vignettebutton').each(function() {
             
             $(this).wrap('<div class="buttonwrap">');
             $(this).find('.middle').before('<span class="block"></span><span class="front"></span>');
             $(this).append('<span class="back"></span><span class="clear"></span>');
             $(this).find('.block').width($(this).width());
         });

         if($('#tabs-nav')){
            $('#tabs-nav').tabs();
            $('#tabs-nav .link').each(function(){
                $(this).click(function() { // bind click event to link
                    
                    if($(this).hasClass('bt-next')){
                        $('#tabs-nav').tabs('select',(parseInt($(this).attr('rel'))+1)); // switch to next tab
                    }else{
                        $('#tabs-nav').tabs('select',($(this).attr('rel')-1)); // switch to prev tab
                    }
                });
            });
            $('#tabs-nav').bind('tabsselect', function(event, ui) {
                return (checkFields($('#tabs-nav').tabs('option', 'selected')));
                //alert(ui.panel.id);
            });
         }
        $('#main-nav1 li').hover(
            function () {
                //show its submenu
                $('ul', this).slideDown(500);

            },
            function () {
                //hide its submenu
                $('ul', this).slideUp(500);
            }
        );

    $("#main-nav li").hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 50,   // number = milliseconds for onMouseOver polling interval
        over: show,     // function = onMouseOver callback (required)
        timeout: 300,   // number = milliseconds delay before onMouseOut
        out: hide       // function = onMouseOut callback (required)
    });

       //photographers area dropdown login
      $('.memberLogoff #header .dropdown').hide();

      $('.memberLogoff #header .dropdown, .memberLogoff #header #li-member').hover(
        function() {
          $('.memberLogoff #header .dropdown').show();
          $('.memberLogoff #header .dropdown').slideDown('fast').addClass('open');
        },
        function () {
            //hide its submenu
            $('.memberLogoff #header .dropdown').hide();
            $('.memberLogoff #header .dropdown').slideUp('fast').removeClass('open');
                
      });

      $('#text-pass').focus(function(){
          $('#text-pass').hide();
          $('#top-pass').show();
          $('#top-pass').focus();
      });
      $('#top-pass').blur(function(){
          if($(this).val()=='Password' || ($(this).val()=='')){
            $('#top-pass').hide();
            $('#text-pass').show();
          }
      });

      $('#top-name').focus(function(){
          if($(this).val()=='Username') $(this).val('');
      });
      $('#top-name').blur(function(){
          if(($(this).val()=='')) $(this).attr('value','Username');
      });

    $("a.slideshow").fancybox({
        'speedIn'		:	600,
        'speedOut'		:	200,
        'padding'       :   0,
        'overlayShow'	:	true,
        'showCloseButton'	: true,
        'titlePosition' 		: 'inside',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return ''+ (title && title.length ?  title + ' - '  : '' ) + (currentIndex + 1) + ' of ' + currentArray.length + '';
		}

    });
    
    $("a.fancybox").fancybox({
        'speedIn'		:	600,
        'speedOut'		:	200,
        'overlayShow'	:	true,
        'showCloseButton'	: true,
        'titlePosition' 		: 'inside'
    });

    $("a.fancybox2").fancybox({
        'type'          :   'iframe',
        'speedIn'		:	600,
        'speedOut'		:	200,
        'width'         :   487 ,
        'height'        :   448
    });

    $("a.fancybox3").fancybox({
        'speedIn'			:	600,
		'speedOut'			:	200,
        'overlayShow'		:	true,
        'showCloseButton'	:	true,
        'titlePosition' 	:	'inside',
        'padding'			:	10,
		'autoScale'			:	true
    });


    $('.bt-view-offer').click(function(){
        idName = $(this).attr('rel');
        if ($(idName).length){
            $('#accordion').accordion('activate', $(idName));
        }
    });
	$('#shipcountry').change(function(){
		if($(this).val()==99)
		{
			$('#other-country').show();
		}
		else
		{
			$('#other-country').hide();
		}
			
	});
});
})(jQuery);

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
}

function toggle(div)
{
	if ($('#'+div).css('display') == 'block')
		$('#'+div).hide();
	else
		$('#'+div).show();
	
    if($('input[name=shippingmethod]:checked').val()=='collect'){
		$('#shipaddress').val("COLLECT") ;
		$('#shipaddress2').val("COLLECT");
		$('#shipcity').val("COLLECT");
		$('#shipcounty').val("COLLECT");
		$('#shippostcode').val("COLLECT");
		$('#updateCheckbox').hide();
    }else{

		$('#shipattn').val($('name').val()) ;
		$('#shipaddress').val($('#address').val()) ;
		$('#shipaddress2').val($('#address2').val()) ;
		$('#shipcity').val($('#city').val()) ;
		$('#shipcounty').val($('#county').val())  ;
		$('#shippostcode').val($('#postcode').val()) ;
		$('#updateCheckbox').show();
    }
}

function updateAddresses(myBox)
{
	if (myBox.checked == false) {
		$('#shipattn').val($('#name').val()) ;
		$('#shipaddress').val($('#address').val()) ;
		$('#shipaddress2').val($('#address2').val()) ;
		$('#shipcity').val($('#city').val()) ;
		$('#shipcounty').val($('#county').val()) ;
		$('#shippostcode').val($('#postcode').val()) ;

	} else if (myBox.checked == true) {
		$('#shipattn').val('') ;
		$('#shipaddress').val('');
		$('#shipaddress2').val('');
		$('#shipcity').val('');
		$('#shipcounty').val('') ;
		$('#shippostcode').val('');
	}
}

function validateForm()
{
	if ($('#shipaddress').val()=='')
	{
		alert("Please fill in your shipping address.");
		return false;
	}
	return true;
}

function checkpostcode(evt)
{

 var charCode = (evt.which) ? evt.which : event.keyCode

 if (charCode== 189 || charCode == 190 || charCode == 191|| charCode == 220)
    return false;

 return true;
}

function fancyAlert(data){
    $j.fancybox(data,{
            'autoDimensions'	: false,
			'width'         		: 350,
			'height'        		: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
        
    });
}

function fancyError(id,error){
    $j('#'+id).append('<div class="fancyError"><div class="border">'+error);
}
function show() {
    var menu = $(this);
    menu.children("ul:first").slideDown();
}

function hide() {
    var menu = $(this);
    menu.children("ul:first").slideUp();

}	
