﻿var homePage = function($){
    var priv = {
          
          bindPromoBlockEvents  : function(){
            $("#homepagerighttop div.promo-block li").bind("click",
                function(){
                    document.location.href = $(this).find("a").attr("href");
                }
            ).hover(
                function(evt){
                    $(this).addClass("hover");
                },
                function(evt){
                    $(this).removeClass("hover");
                }
            );
          },
          
          writeFlashBanner : function() {
            try {
                var flashWidth = 437;
                var flashHeight = 174;
                var flashFile = resources.skin_path + $('#brochure-flash span').text();
                $('#brochure-flash').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+flashWidth+'" height="'+flashHeight+'">'+
                    '<param name="allowScriptAccess" value="sameDomain" />'+
                    '<param name="movie" value="'+flashFile+'" />'+ 
                    '<param name="quality" value="high" />'+
                    '<param name="bgcolor" value="#ffffff" />'+
                    '<embed src="'+flashFile+'" quality="high" bgcolor="#ffffff" width="'+flashWidth+'" height="'+flashHeight+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
                '</object>');
                            
                $('#brochure-flash object').get(0).outerHTML = $('#brochure-flash object').get(0).outerHTML;
             }
             catch(err){
                //nice catch
             }          
          
          },
          
         inputSubmit    : function(){
             if($('#homesearch').val() != null && $('#homesearch').val() != ""){
                $('#homesearch').val($('#homesearch').val().replace('bijv: ',''));
                $('#form-search').get(0).submit();
            }
         }       
    };
    
    return {
        
        /**
		 * should be triggered on $(document).ready
		 */
		OnReady	: function(){	
		
		   //add hyperlink to clickable objects
		   $('.clickable').click(function(){
		      document.location.href = $('span.link',this).attr('rel');
		   });		   
		     
            		
			priv.bindPromoBlockEvents();
			
			$('#homepagetopleft').bind("click",
                function(){                   
                    document.location.href = resources.path_prefix + '/search.aspx';
                    return false;
                }
            );
			
			$('#country-box').bind("click",
                function(){
                    //redirect to the correct page
                    var url = $(this).find("a.countryurl").attr("href");
                    
                    document.location.href = url;
                    //prevent event bubbling
                    return false;
                }
            );
            if($('#country-box .hidden').text().indexOf('.jpg') != -1){
                $('#randombox-content').css('background','url('+$('#country-box .hidden').text()+') right top no-repeat');
            }
            
            $('#homesearch').bind("click",
                function(){
                    this.value = '';
                }
            ).bind("keyup",
                function(evt){
                    if(evt.keyCode == 13){
                        priv.inputSubmit();
                    }
                }
            );
            	
            $('#homesearchbutton').bind("click",
                function(){
                   priv.inputSubmit();
                }
            );
            
            priv.writeFlashBanner();
		}
        
    };
}(jQuery);
