function urlencode (str) {
str = escape(str);
return str.replace(/[*+\/@]|%20/g,
function (s) {
switch (s) {
case "*": s = "%2A"; break;
case "+": s = "%2B"; break;
case "/": s = "%2F"; break;
case "@": s = "%40"; break;
case "%20": s = "+"; break;
}
return s;
}
);
}


// jQuery Plugin equalHeight

(function($) {
$.fn.equalHeight = function() {
var group = this;
$(window).bind('resize', function(){
var tallest = 0;
$(group).height('auto').each(function() {
tallest = Math.max(tallest, $(this).height());
}).height(tallest);
}).trigger('resize');
}
})(jQuery) 


$(document).ready(function() {


//flowplayer

jQuery(".flowplayer").each(function(i){
    hgt = $(this).find('img').height();
    wid = $(this).find('img').width();
    $(this).css('width', wid).css('height', hgt);
    $(this).prepend('<span class="player-start">Start</span>');
    $('.player-start').fadeTo(0, 0.7);
});
flowplayer(".flowplayer", "/flash/flowplayer-3.2.7.swf");

$('.0').remove();

path = window.location;
//alert(path);

if($(".module-menu").length > 1){
$(".module-menu:first").remove();
}

if($(".pathway li").length == 1){
$(".pathway").remove();
}

if(path == 'http://www.brunswick.dev.binn.ru/address/' || path == 'http://brunswick.dev.binn.ru/address/'){
$(".module-menu li:nth-child(3)").remove();
}

$("#oborudovanie .inputbox").each(function(){
if ($(this).attr("value") == "" || $(this).attr("value") == "0"){
$(this).attr("value", $(this).attr("title"));
}
});

$("#oborudovanie .inputbox").focus(function(){
if ($(this).attr("value") == $(this).attr("title")){
$(this).attr("value", "");
}
});

$("#oborudovanie .inputbox").blur(function(){
if ($(this).attr("value") == ""){
$(this).attr("value", $(this).attr("title"));
}

$("#oborudovanie .button").click(function(){
if($("#oborudovanie .number").attr("value") == $("#oborudovanie .number").attr("title")){
$("#oborudovanie .number").attr("value", "");
}
});
});


/*----------------------------------------------------------------------    
Enable selectBox control and bind events
----------------------------------------------------------------------*/
if($('#f_1').length > 0){
	$('#f_3').find('option:first').attr('selected', true);
}
$(".selectbox").selectBox(); 

//send filter form
$(".filterSel").change(function(){
	$("#filterForm").submit();
});

//send ajax filter form
function loadData(){
	url = window.location.href;
	$("#filterForm").find('select').each(function(e){
		url += e == 0 ? '?' : '&';
		url += $(this).attr('name') + '=' + $(this).find('option:selected').val();
	});
	
	$("#bowl-list").html('<div style="margin:30px 20px 20px; font-size: 14px;">Выполняется загрузка. <br />Пожалуйста, подождите...</div>');
	
	$("#bowl-list").load(url + ' #bowl-list');
	$(".bowl-list:first").html($(".bowl-list:last").html());
}
function loadCityRegion(){
	countryId = $('#f_1').val()*1;
	if(countryId != ''){
		url = '/address/ajax.php?type=1&c_id=' + countryId;
		$.get(url, function(data){
			regionsCountry = [267,268,271,273];
			if($.inArray(countryId, regionsCountry) != -1){
				data = '<option value="">Все регионы</option>' + data;
				$('#f_2').html(data);
				$('#f_3').html('<option value="">Все города</option>');
			} else {
				data = '<option value="">Все города</option>' + data;
				$('#f_3').html(data);
				$('#f_2').html('<option value="">Все регионы</option>');
			}
			$('#f_2').selectBox('destroy').selectBox();
			$('#f_3').selectBox('destroy').selectBox();
			
			loadData();
		});
	}
}

function loadCity(){
	countryId = $('#f_2').val()*1;
	if(countryId != ''){
		url = '/address/ajax.php?type=1&c_id=' + countryId;
		$.get(url, function(data){
			
			data = '<option value="">Все города</option>' + data;
			$('#f_3').html(data);
			$('#f_3').find('option:first').attr('selected', true);
			$('#f_3').selectBox('destroy').selectBox();
			
			loadData();
		});
	}
}

$("#f_1").unbind('change').change(function(){
	loadCityRegion();
});

$("#f_2").unbind('change').change(function(){
	loadCity();
});

$("#f_3, #f_4").unbind('change').change(function(){
	loadData();
});


});

$(document).ready(function() {

/*----------------------------------------------------------------------
COOKIES
----------------------------------------------------------------------*/
setCookie = function(name, value, expires, path) {
var cookie = name + '=' + value;
if (expires) {
cookie += '; expires=' + expires.toGMTString();
}
if (path) {
cookie += '; path=' + path;
}
document.cookie = cookie;
};

getCookie = function(name) {
var nameEQ  = name + '=';
var ca      = document.cookie.split(';');

for (var i = 0; i < ca.length; i++) {
var c = ca[i];

while (' ' == c.charAt(0)) {
c = c.substring(1,c.length);
}
if (0 == c.indexOf(nameEQ)) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
};

unsetCookie = function(name) {
var date = new Date();
date.setTime(date.getTime() - 1);
setCookie(name, '', date);
};


/*---------------------------------------------------------------------- 
MEGA MENU
----------------------------------------------------------------------*/
//$(['balls','bags','accessories','shoes','the-pros','products','parts','lane-maintenance','service-and-support','bowling-investment','modernization']).each(function(i){
$(['sub_1','sub_2','sub_3','sub_4','sub_5','sub_6','sub_7','sub_8','sub_9']).each(function(i){
var nav = this;

$("#nav li."+ nav +" > a").hover(function(){
var li = $(this).parent();

$('#nav > li.on').mouseleave();
li.addClass('on');

var $anchor = $(this);
var $megamenuContainer = $('.mm-'+ nav);

if ($megamenuContainer.size() == 1) {
if(li.find(".mega-inner").size()) {

li.addClass("mm");
$megamenuContainer.show();

}
} else {
var loading = null;

var $megamenuContent = $('<div class="mega-menu mm-'+nav+'"><div class="content"></div></div>');

$anchor.after($megamenuContent);

loading = $.get('../megamenu/'+ nav, function(data) {

var $data = $(data);
var size = $data.find(".list").size();
var w = (size*215)+15;

if(size == 4) {

if(i != 0) {
$megamenuContent.width(w).css({'margin-left': '-'+ (w/2) +'px', 'left': '50%'});
} else {
$megamenuContent.width(w).css({'left': '0'});
}

} else if(size == 1 || size == 2) {

if(i != 0) {
$megamenuContent.width(w).css({'margin-left': '-20px','left': '0'});
$megamenuContent.parents("li."+ nav).css({'position': 'relative'});  // IE7 FIX
} else {
$megamenuContent.width(w).css({'left': '0'});
}

} else {

if(i == 3) {
$megamenuContent.width(w).css({'right': '0'});
} else if(i == 0) {
$megamenuContent.width(w).css({'left': '0'});
} else {
$megamenuContent.width(w).css({'margin-left': '-20px','left': '0'});
$megamenuContent.parents("li."+ nav).css({'position': 'relative'}); // IE7 FIX
}

}

$megamenuContent.children(".content").html(data);

if(li.hasClass("on")) {
if(li.find(".mega-inner").size()) {
$megamenuContent.show();
li.addClass("mm");
}
}

});

}

//
$(".mega-inner li").unbind()
//

li.mouseleave(function(){

$('.mm-' + nav).hide();
li.removeClass("mm");

});

}, function(){

$(this).parent().removeClass("on");

});
});

});

$.fn.input = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
$(this).val("");
$(this).addClass("focus");
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
$(this).removeClass("focus");
}
});
};

$(document).ready(function() {

/*----------------------------------------------------------------------    
MISC SCRIPTS
----------------------------------------------------------------------*/

//    $("a[href*=.pdf]").click(function(){
//        window.open(this.href);
//        return false;
//    });

$("#header input[type='text']").input();
$("#related-list").hide();
$("#information-docs").hide();
$(".pro-tip").hide();

$("#might-also-like").click(function(){
$("#related-list").slideToggle();
return false;
});
$("#more-information").click(function(){
$("#information-docs").slideToggle();
return false;
});
$("#pro-tips").click(function(){
$(".pro-tip").slideToggle();
return false;
});

$("#footer ul li:last-child, #subnav li:last-child, .breadcrumb li:last, #related-list li:last").addClass("last");

if($.browser.msie) {
var showWarning = getCookie('ieWarning');

if(showWarning == "show"){
$('<div id="browser-warning"><h2><span>You are viewing our site with an outdated browser! <a href="http://www.getfirefox.com/">Click here</a> to download a new browser and properly view our site.</span></h2></div>').insertBefore('#wrapper');
}
}

/*----------------------------------------------------------------------    
Ñêðóãëåíèå óãëîâ ó ÈÅ...
----------------------------------------------------------------------*/
if ($.browser.msie) {
//$("#header #email-search input").css('background', '#FFFFFF');
//$("#header #signup-address").corner("2px");
}

/*----------------------------------------------------------------------    
HOMEPAGE SLIDESHOW
----------------------------------------------------------------------*/
if ($.browser.msie) {
if($('#slideshow').length != 0) {
$('#slideshow .slides').cycle({
fx: 'fade',
speed:  700, 
timeout: 7000,
next: '.counter .next',
prev: '.counter .previous',
pager:  '.counter ul',
cleartypeNoBg: true,
pagerAnchorBuilder: function(idx, img){ 
return '<li><a href="#">' + (+idx+1) + '</a></li>';
}
});
}
} else {
if($('#slideshow').length != 0) {
$('#slideshow .slides').cycle({
fx: 'fade',
speed:  700, 
timeout: 7000,
next: '.counter .next',
prev: '.counter .previous',
pager:  '.counter ul',
pagerAnchorBuilder: function(idx, img){ 
return '<li><a href="#">' + (+idx+1) + '</a></li>';
}
});
}
}


if($('#banner .slides').length != 0) {
var $banner = $('#banner .slides').cycle({
fx: 'fade',
speed:  400, 
timeout: 0
});

var color = $("#color-id").text();

$("#colors li").each(function(i){
$(this).click(function(){
$banner.cycle(i);
color = $("a",this).attr("title");
$("#color-id").text(color);
return false;
});
});

$("#colors li").hover(function(){
$("#color-id").text($("a",this).attr("title"));
},function(){
$("#color-id").text(color);
});
}


/*----------------------------------------------------------------------    
FILTERS/SELECT BOXES
----------------------------------------------------------------------*/
$("#filter .styled").change(function(){
if($(this).attr("id") == "height" && $(":selected",this).val() == "6-foot") {
document.getElementById('lanes').selectedIndex = 0;
$("#selectl").text($("#lanes option:first").text());
}
if($(this).attr("id") == "hook-potential") {
document.getElementById('breakpoint-shape').selectedIndex = 0;
$("#selectb").text($("#breakpoint-shape option:first").text());
document.getElementById('alphabetical').selectedIndex = 0;
$("#selecta").text($("#alphabetical option:selected").text());
}
if($(this).attr("id") == "breakpoint-shape") {
document.getElementById('hook-potential').selectedIndex = 0;
$("#selecth").text($("#hook-potential option:first").text());
document.getElementById('alphabetical').selectedIndex = 0;
$("#selecta").text($("#alphabetical option:first").text());
}
if($(this).attr("id") == "alphabetical") {
document.getElementById('hook-potential').selectedIndex = 0;
$("#selecth").text($("#hook-potential option:first").text());
document.getElementById('breakpoint-shape').selectedIndex = 0;
$("#selectb").text($("#breakpoint-shape option:first").text());
}

this.form.submit();
});

$("#select-ball,#select-contact, #select-category").change(function(){
var val = $(this).val();
if(val != "")
window.location = val;
});


/*----------------------------------------------------------------------    
PRO NEWS SCROLLER
----------------------------------------------------------------------*/
if($('#pro-news').length != 0) {
$("#pro-news").liScroll({travelocity: 0.05}); 
}


$("#locate-rep").click(function(){
$("#continent").val($("#locate-country option:selected").attr("data-continent"));
});

/*----------------------------------------------------------------------    
CART LINK OPEN
----------------------------------------------------------------------*/

$("div.also-module").hide();
$("#cart-link li.parrent a").click(function() {
$(this).parent().find("div.also-module").toggle("blind");
});

if($("div.feedback p.form-info").length > 0){
$("div.also-module").show();
}


//$("#leftcolumn ul.archive").hide();
if($("#leftcolumn li.action").hasClass("active")){
$("#leftcolumn ul.archive").show();
}else{
$("#leftcolumn ul.archive").hide();
}
$("#leftcolumn li.action > a").click(function() {
$(this).parent().find("ul.archive").toggle("blind");
});


// Colorbox
flag = $(".cbox");
if(flag.length > 0){
$(".cbox").colorbox({current:"{current} из {total}"});
};

flag = $(".small-cbox");
if(flag.length > 0){
$(".small-cbox").each(function(){
var idx = $(this).attr("rel");
$(this).colorbox({width: "500px", inline:true, href:".doc_text_"+idx});
});
};


flag = $(".cbox2");
if(flag.length > 0){
$(".cbox2").colorbox({
current:"{current} из {total}"
});
};


$(".category-items").each(function(){
    $(this).find(".category-item-inn:first-child").remove();
});

if(window.location.search != ''){
	$(".category").hide();
	//alert(window.location.search);
	$(".category-items").each(function(){
		var idx = $(this).attr("rel");
		$(".added_" + idx).show();
	});
}


});


/*----------------------------------------------------------------------    
EQUALIZE HEIGHTS
----------------------------------------------------------------------*/
$(window).load(function() {
var sidebar = $("#sidebar").height();
var content =  $("#content").height()+290;

if(sidebar > content) {
$("#content").css("min-height", sidebar-322);
}
});


/*----------------------------------------------------------------------    
EMAIL SIGNUP
----------------------------------------------------------------------*/

$('#email-signup').submit(function(e){
e.preventDefault();
var emailAddress = $('#email-signup input').val();

if(emailAddress != "" && emailAddress != "ïîäïèñàòüñÿ íà íîâîñòè" && emailAddress != "ïîäïèñàòüñÿ íà íîâîñòè "){
var url = '/email-signup/_signup-form/?email=' + urlencode(emailAddress);
} else {
var url = '/email-signup/_signup-form/';
}

});

if(jQuery().filestyle) {
$("#rollers input[type=file]").filestyle({ 
image: "http://system.brunswickbowling.com/assets/images/file-upload.png",
imageheight : 22,
imagewidth : 82,
width : 250
});
}

$('#rollers form .date-val').keyup(function(){
var month = $('#roller-month').val();
var day = $('#roller-day').val();
var year = $('#roller-year').val();
$('#date-field').val(year + '-' + month + '-' + day + ' 00:00');
});

$('#rollers form .date-val').change(function(){
var month = $('#roller-month').val();
var day = $('#roller-day').val();
var year = $('#roller-year').val();
$('#date-field').val(year + '-' + month + '-' + day + ' 00:00');
});

$('#rollers form #roller-name').keyup(function(){
var name = $(this).val();
$('#entry-title').val(name);
});

$('#rollers form #roller-name').change(function(){
var name = $(this).val();
$('#entry-title').val(name);
});



$(window).load( function() {

// Auto Height Column
$("#list .item a.title").equalHeight();

});
